Thinking in a Simple Way

搭好梯子再上来 https://simpleface.wordpress.com

JAVA inheritance(IS a & HAS a relationship)


Closely related classes could be arranged using two types of relationship:

  • is a “, the inheritance relationship, A is a type of B.
  • has a “, the composition relationship, A has a B.

If A and B are of the same type, but A is more specific and B is more general, A shares all the properties/behaviours of B, we can use the “is a” relationship, e.g A extends B.

public class salariedEmployee extends Employee

{

// contents

}

we can say salariedEmployee is a Employee

or salariedEmployee is a type of Employee

when a class implements an interface, the same is-a relationship provided by inheritance applies.

for example,

public abstract class Employee implements Payable

{

}

Payable is an interface,

we can say Employee is a  Payable. or Employee is a type of Payable.

just as we can

assign the object reference to the superclass type as:

// in Test.java
 Account sister = new SAccount("s345","Judy Brown",1000,200);
sister.deposit(500); // superclass method

sister.withdraw(100);// overridden method
we can also assign the reference of a subclass object to an interface Type(variable).
 Payable sister = new SalariedEmployee("dd");
Advertisements

abstract class and interface (java)


An abstract class is to provide an appropriate super-class from which other classes can inherit and thus share a common design.

An abstract can have a set of concrete methods and abstract methods.

Classes can be used to instantiate objects are called concrete classes.

Interface means that Java offers a capability that requires that unrelated classes implement a set of common method.

An interface only contains constants and abstract methods.

unlike classes, all interface elements must be public, and interface may not specify any implementation details.

If a new method is added into an interface, you must perform or add this method to every classes that implement that interface.

A class that does not implement all the methods of the interface is an abstract class and must be declared abstract.

An interface is typically used when unrelated classes need to share common methods and constants. This allows objects of unrelated classes to be processed polymorphically- objects of classes that implement the same interface can respond to the same method calls.

*if an  abstract class implements an interface, we do not need to declare  the interface methods

as abstract in the abstract class,  they are already implicitly declared as such in the interface.

any concrete subclass of the abstract class must implement the interface methods to fulfill the superclass’s contract with the compiler.

任何一个实现了一个Java接口所规定的方法的类都可以具有这个接口的类型,而一个类可以实现任意多个Java接口,从而这个类就有了多种类型

 

 

java 循环语句for(int a:list)冒号的意思


例如你的数组名字为
int[] list = new int [15];  //该数组有15个元素,从0个元素开始一直到第14个结束
for(int index =0; index<15;index++)
list[index]= index*5;  //编辑一个简单的乘法公式,把所有的15个数分别乘进去;
for(int a : list)
System.out.print(a + " ");

冒号指迭代,即不断从数组的List里取其中的元素,
赋值给临时变量a,从JDK1.5开始,冒号就可以实现很方便的读取List里的内容了。
输出结果如下:

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70
这15个数组的变化规律
【0】= 0 ×5 =0
【1】=1*5 = 5
【2】=2*5 = 10
 直到最后一个元素,以此类推

Database SQL Exercise (1)


The Online Movies DataBase (OMDB) is as follows:
MovieInfo (mvID, title, rating, year, length, studio)
Director(directorID, firstname, lastname)
Member(username, email, password)
Actor(actorID, firstname, lastname, gender, birthplace)
Cast(mvID*, actorID*)
Direct(mvID*, directorID*)
Genre(mvID*, genre)
Ranking(username*, mvID*, score, voteDate)

a) Find the movies whose studio information is not available or whose genre
information is not available. List the movid and title of these movies. You must
use the NOT EXISTS operator. You must not use any SET operator (e.g. UNION,
MINUS)

Select mvID, title from MovieInfo WHERE NOT EXISTS( SELECT * FROM GENRE

WHERE GENRE.mvID = MoiveInfo.mvID) OR MovieInfo.studio is Null;

Mac OS X 快捷键 大全


了解常见 Mac OS X 快捷键。快捷键方式即通过按下键盘上的组合键来调用 Mac OS X 中的功能。

要使用快捷键或组合键,您可以同时按修饰键和字符键。例如,同时按下 Command 键(标有  符号的按键)和“c”键会将当前选中的任何内容(文本、图形等等)拷贝至夹纸板。这也称作 Command-C 组合键(或快捷键)。

许多组合键中都包含修饰键。修饰键将改变 Mac OS X 对其他键击或鼠标点按动作的解释方式。修饰键包括 Command、Control、Option、Shift、Caps Lock 和(仅限便携式 Mac)fn 键。

以下是出现在 Mac OS X 菜单中的修饰键符号:

(Command 键)- 有些时候称为“Apple 键”;在 Apple 键盘上此按键还会有 Apple 标志 ()
(Control 键)
(Option 键)- 此按键上也可能标记“Alt”
(Shift 键)
 (Caps Lock) – 切换大写字母锁定的开或关
fn(功能键)- 位于便携式 Mac 上内建键盘的左下角

受影响的产品

Mac OS X 10.4, Mac OS X 10.3, Mac OS X 10.2, Mac OS X 10.1, Mac OS X 10.0, Mac OS X 10.5

启动快捷键

按下按键或组合键直至执行/进入预期功能(例如,在启动过程中按住 Option 直至进入“启动管理器”,或在启动过程中按住 Shift 直至执行“安全启动”)。提示:如果启动功能未起作用,而此时您使用的是第三方键盘,请连接 Apple 键盘,然后再试一次。

按键或组合键 功能
Option 显示所有可引导宗卷(启动管理器
Shift 执行安全启动(以安全模式启动)
C 从可引导磁盘启动
T 以 FireWire 目标磁盘模式启动
N 从 NetBoot 服务器启动
X 强制 Mac OS X 启动(存在非 Mac OS X 的启动宗卷时)
Command-V 详细模式启动
Command-S 单用户模式启动


Finder 快捷键

组合键 功能
Command-A 选中最前面的 Finder 窗口中的所有项(如果未打开任何窗口则选中桌面内容)
Option-Command-A 取消选择所有项
Shift-Command-A 打开“应用程序”文件夹
Command-C 拷贝所选项/文本
Shift-Command-C 打开“电脑”窗口
Command-D 复制所选项
Shift-Command-D 打开桌面文件夹
Command-E 推出
Command-F 查找任何匹配 Spotlight 属性的内容
Shift-Command-F 查找 Spotlight 文件名匹配项
Option-Command-F 转至已打开 Spotlight 窗口中的搜索栏
Shift-Command-G 前往文件夹
Shift-Command-H 打开当前所登录用户帐户的个人文件夹
Command-I 查看简介
Option-Command-I 显示检查器
Control-Command-I 查看摘要信息
Shift-Command-I 打开 iDisk
Command-J 查看“显示”选项
Command-K 连接服务器
Shift-Command-K 打开“网络”窗口
Command-L 为所选项创建替身
Command-M 最小化窗口
Option-Command-M 最小化所有窗口
Command-N 新建 Finder 窗口
Shift-Command-N 新建文件夹
Option-Command-N 新建智能文件夹
Command-O 打开所选项
Shift-Command-Q 注销
Option-Shift-Command-Q 立即注销
Command-R 显示(替身的)原身
Command-T 添加到工具条
Shift-Command-T 添加到个人收藏
Option-Command-T 在 Finder 窗口中隐藏工具栏/显示工具栏
Shift-Command-U 打开“实用工具”文件夹
Command-V 粘贴
Command-W 关闭窗口
Option-Command-W 关闭所有窗口
Command-X 剪切
Option-Command-Y 幻灯片显示(Mac OS X 10.5 或更高版本)
Command-Z 还原/重做
Command-1 显示为图标
Command-2 显示为列表
Command-3 显示为分栏
Command-4 显示为 Cover Flow(Mac OS X 10.5 或更高版本)
Command-,(Command 加逗号键) 打开 Finder 偏好设置
Command-`(重音符键 – US 英语键盘布局中 Tab 键的上方) 循环显示打开的 Finder 窗口
Command-Shift-? 访问 Mac 帮助
Option-Shift-Command-esc 强制退出 Finder
Command-[ 后退
Command-] 前进
Command-上箭头 打开父文件夹
Control-Command-上箭头 在新窗口中打开父文件夹
Command-下箭头 打开高亮显示的项
Command-Tab 切换应用程序 – 向前循环
Shift-Command-Tab 切换应用程序 – 向后循环
Command-Delete 移到废纸篓
Shift-Command-Delete 清倒废纸篓
Option-Shift-Command-Delete 清倒废纸篓(不显示确认对话框)
空格键(或 Command-Y) 快速查看(Mac OS X 10.5 或更高版本)
拖移时按 Command 键 将拖移的项移到其他宗卷/位置(按住键时指针图标发生变化 – 请参阅此文章
拖移时按 Option 键 拷贝拖移的项(按住键时指针图标发生变化 – 请参阅此文章
拖移时按 Option-Command 组合键 为拖移的项创建替身(按住键时指针图标发生变化 – 请参阅此文章


应用程序和其他 Mac OS X 键盘命令

注意:有些应用程序可能不支持如下全部应用程序组合键。

组合键 功能
Command-空格键 显示或隐藏 Spotlight 搜索栏(如果安装了多语种,则可能循环显示启用的语系)
Option-Command-空格键 显示 Spotlight 搜索结果窗口(如果安装了多语种,则可能循环显示某一语系下的键盘布局和输入法)
Command-Tab 在打开的应用程序的列表中,向下移动到下一个最近使用的应用程序
Shift-Command-Tab 在打开的应用程序的列表中向上移动(按最近使用时间排序)
Shift-Tab 按反方向浏览各控件
Control-Tab 聚焦对话框中的下一组控件或聚焦下一个表格(当 Tab 移到下一个单元格时)
Shift-Control-Tab 聚焦上一组控件
Command-esc 打开 Front Row(如果已安装)
Option-Eject 从备选光盘驱动器中推出(如果已安装)
Control-Eject 显示关机对话框
Option-Command-Eject 使电脑进入睡眠模式
Control-Command-Eject 退出所有应用程序(在此之前会给您机会存储对已打开文稿所作的更改),然后重新启动电脑
Control Option-Command-Eject 退出所有应用程序(在此之前会给您机会存储对已打开文稿所作的更改),然后关闭电脑
fn-Delete 向前删除(适用于便携式 Mac 的内建键盘)
Control-F1 切换全键盘控制的开或关
Control-F2 聚焦菜单栏
Control-F3 聚焦 Dock
Control-F4 聚焦活跃窗口或下一个窗口
Shift-Control-F4 聚焦上一个活跃窗口
Control-F5 聚焦工具栏
Control-F6 聚焦第一个(或下一个)面板
Shift-Control-F6 聚焦上一个面板
Control-F7 临时覆盖窗口和对话框中的当前键盘访问模式
F9 平铺或取消平铺所有打开的窗口
F10 平铺或取消平铺当前活跃应用程序中所有打开的窗口
F11 隐藏或显示所有打开的窗口
F12 隐藏或显示 Dashboard
Command-` 激活最前面的应用程序中下一个打开的窗口
Shift-Command-` 激活最前面的应用程序中上一个打开的窗口
Option-Command-` 聚焦窗口抽屉
Command- -(减号) 缩小所选项
Command-{ 使所选内容左对齐
Command-} 使所选内容右对齐
Command-| 使所选内容居中
Command-: 显示“拼写”窗口
Command-; 查找文稿中存在拼写错误的词
Command-, 打开最前面的应用程序的偏好设置窗口(前提是应用程序支持此快捷键)
Option-Control-Command-, 降低屏幕对比度
Option-Control-Command-. 增强屏幕对比度
Command-? 在帮助显示程序中打开应用程序的帮助
Option-Command-/ 打开或关闭字体平滑
Shift-Command-= 放大所选项
Shift-Command-3 将屏幕捕捉到文件
Shift-Control-Command-3 将屏幕捕捉到夹纸板
Shift-Command-4 将所选内容捕捉到文件
Shift-Control-Command-4 将所选内容捕捉到夹纸板
Command-A 高亮显示文稿或窗口中的所有项,或高亮显示文本栏中的所有字符
Command-B 以粗体显示所选文本或切换文本粗体显示的开/关
Command-C 复制所选数据并存储到夹纸板
Shift-Command-C 显示“颜色”窗口
Option-Command-C 拷贝所选文本的样式
Control-Command-C 拷贝所选项的格式设置并存储到夹纸板
Option-Command-D 显示或隐藏 Dock
Command-Control D 在字典应用程序中显示所选词的定义
Command-E 使用所选内容进行查找
Command-F 打开“查找”窗口
Option-Command-F 移到搜索栏控件
Command-G 查找所选内容出现的下一个位置
Shift-Command-G 查找所选内容出现的上一个位置
Command-H 隐藏当前正在运行的应用程序窗口
Option-Command-H 隐藏所有其他正在运行的应用程序窗口
Command-I 以斜体显示所选文本或切换文本斜体显示的开/关
Option-Command-I 显示检查器窗口
Command-J 滚动到所选部分
Command-M 将活跃窗口最小化至 Dock
Option-Command-M 将活跃应用程序的所有窗口最小化至 Dock
Command-N 在最前面的应用程序中创建新文稿
Command-O 在最前面的应用程序中显示用于选择要打开的文稿的对话框
Command-P 显示“打印”对话框
Shift-Command-P 显示用于设定打印参数的对话框(页面设置)
Command-Q 退出最前面的应用程序
Command-S 存储活跃文稿
Shift-Command-S 显示“存储为”对话框
Command-T 显示“字体”窗口
Option-Command-T 显示或隐藏工具栏
Command-U 对所选文本加下划线或切换加下划线/去掉下划线
Command-V 在插入点位置粘贴夹纸板内容
Option-Command-V 将某对象的样式应用于所选对象(粘贴样式)
Option-Shift-Command-V 将周围文本的样式应用于所插入对象(粘贴并匹配样式)
Control-Command-V 将格式设置应用于所选对象(粘贴标尺命令)
Command-W 关闭最前面的窗口
Shift-Command-W 关闭文件及其关联窗口
Option-Command-W 不退出应用程序直接关闭其所有窗口
Command-X 移去所选内容并存储到夹纸板
Command-Z 还原上一命令(有些应用程序允许多次还原)
Shift-Command-Z 重做上一命令(有些应用程序允许多次重做)
Control-右箭头 聚焦视图(如表格)内的另一个值或单元格
Control-左箭头 聚焦视图(如表格)内的另一个值或单元格
Control-下箭头 聚焦视图(如表格)内的另一个值或单元格
Control-上箭头 聚焦视图(如表格)内的另一个值或单元格
Shift-Command-右箭头 选中插入点至当前行行尾之间的文本 (*)
Shift-Command-左箭头 选中插入点至当前行行首之间的文本 (*)
Shift-右箭头 将文本选择向右扩展一个字符 (*)
Shift-左箭头 将文本选择向左扩展一个字符 (*)
Shift-Command-上箭头 选中插入点至文稿起始位置之间的文本 (*)
Shift-Command-下箭头 选中插入点至文稿结束位置之间的文本 (*)
Shift-上箭头 将文本选择紧邻字符边界按相同水平位置向上扩展一行 (*)
Shift-下箭头 将文本选择紧邻字符边界按相同水平位置向下扩展一行 (*)
Shift-Option-右箭头 将文本选择扩展至当前词词尾,再按一次则扩展至后一词词尾 (*)
Shift-Option-左箭头 将文本选择扩展至当前词词首,再按一次则扩展至前一词词首 (*)
Shift-Option-下箭头 将文本选择扩展至当前段落的结束位置,再按一次则扩展至下一段落的结束位置 (*)
Shift-Option-上箭头 将文本选择扩展至当前段落的起始位置,再按一次则扩展至上一段落的起始位置 (*)
Control-空格键 在当前输入源和上一输入源之间切换
Option-Control-空格键 在所有启用的输入源之间切换
Command-左箭头 将键盘布局更改为系统语系的当前布局
Command-右箭头 将键盘布局更改为罗马语系的当前布局
Option-Command-esc 强制退出

(*) 注意:如果未选择任何文本,则从插入点位置开始扩展。如果通过拖移选择文本,则从所选内容的边界处开始扩展。倒转所选内容的方向会使相应部分取消选择。


万能辅助 – VoiceOver 键盘命令

组合键 功能
Command-F5 或
fn Command-F5
打开或关闭 VoiceOver
Control Option-F8 或
fn Control Option-F8
打开 VoiceOver 实用工具
Control Option-F7 或
fn Control Option-F7
显示 VoiceOver 菜单
Control Option-;
或 fn Control Option-;
启用/停用 VoiceOver Control Option 锁定
Option-Command-8 或
fn Command-F11
开启缩放功能
Option-Command-+ 放大
Option-Command- -(减号) 缩小
Option-Control-Command-8 反转/还原屏幕颜色
Control Option-Command-, 降低对比度
Control Option-Command-. 增强对比度

注意:您可能需要在“键盘”偏好设置中启用“将 F1、F2 等键用作标准功能键”,以使 VoiceOver 菜单和实用工具正常工作。


万能辅助 – 鼠标键

在“万能辅助”偏好设置中打开鼠标键后,您便可以使用键盘或数字小键盘上的键移动鼠标指针。如果电脑没有数字小键盘,则使用 Fn(功能)键。

组合键 功能
8 上移
2 下移
4 左移
6 右移
1 沿对角线向左下角移
3 沿对角线向右下角移
7 沿对角线向左上角移
9 沿对角线向右上角移
5 按鼠标按钮
0 按住鼠标按钮
.(数字小键盘上的句点) 释放按住的鼠标按钮

Apache 防止 DDoS 攻擊


、 mod_evasive 介绍;

mod_evasive 是Apache(httpd)服务器的防DDOS的一个模块。对于WEB服务器来说,是目前比较好的一个防护DDOS攻击的扩展模块。虽然并不能完全防御DDOS攻击,但在一定条件下,还是起到缓服Apache(httpd)服务器的压力。如果配合iptables、硬件防火墙等防火墙设备配合使用,可能有更好的效果。可惜LinuxSir.Org 并没有硬件防火墙,所以是否这种组合效果有更好的效果,我没办法验证。

mod_evasive 的官方地址: http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz


2、 mod_evasive 的安装和配置;


2.1 mod_evasive 的下载地址;

mod_evasive_1.10.1.tar.gz


2.2 mod_evasive 的安装;

安装 mod_evasive 之前,你要用安装Apache(httpd)服务器软件包,还要安装httpd-devel或 apache-dev。在Slackware 12.0中,安装httpd软件即可;

对于Apache 1.x 请用下面的编译方法;

#/usr/sbin/apxs -iac mod_evasive.c

对于Apache 2.x 可以用下面的办法;

#tar zxvf mod_evasive_1.10.1.tar.gz
#cd mod_evasive
#/usr/sbin/apxs -i -a -c mod_evasive20.c

注:apxs 用于编译模块工具;如果是用系统自带的软件包,一般位于/usr/sbin目录。如果您是自己编译安装Apache(httpd)的,你应该自己来指定路径;

我们然后修改/etc/ld.so.conf 文件,把编译出来的动态模块的所在位置指定在 ld.so.conf中;比如我用的是Aapche 2.x ,编译完成后,模块mod_evasive20.so 安装到了 /usr/lib/httpd/modules 目录中;那我们就要把 这个目录写入到ld.so.conf中。

#echo "/usr/lib/httpd/modules" >> /etc/ld.so.conf
#ldconfig

注: 具体要与你的系统环境为准,不要照搬照抄,如果你对Linux不太熟的话;


2.3 mod_evasive 的配置;

在编译安装完成后,会自动插入一行到Apache 配置文件中,对于Apache 2.x 版本中,应该在其配置文件中有类似下面的一行;

LoadModule evasive20_module   lib/httpd/modules/mod_evasive20.so

对于Apache 1.x来说,也应该差不多,大体只是路径不同罢了;

然后我们再修改 Apache 的配置文件,配置文件名为httpd.conf;

在Apache v1.x 版本中,要加入;

<IfModule mod_evasive.c>
DOSHashTableSize    3097
DOSPageCount        2
DOSSiteCount        50
DOSPageInterval     1
DOSSiteInterval     1
DOSBlockingPeriod   10
</IfModule>

在Apache v2.x加入;

<IfModule mod_evasive20.c>
DOSHashTableSize    3097
DOSPageCount        2
DOSSiteCount        50
DOSPageInterval     1
DOSSiteInterval     1
DOSBlockingPeriod   10
</IfModule>

如果您不知道把这些插入到哪,用下面的办法做也是可以的;

在/etc目录中创建一个文件,比如mod_evasive.conf;

#touch /etc/mod_evasive.conf

然后把根据自己的Apache版本来加入相应的内容;

接着我们再修改 httpd.conf ,在最后一行加入

Include /etc/mod_evasive.conf

修改完成后,我们要重启Apache服务器;

比如在Slackware 12.0中,Apache 2.x的重启,我们要用到

#/etc/rc.d/rc.httpd restart

在Redhat、Fededora、Debian、Ubuntu、CentOS中的Apache,可以用;

#/etc/init.d/httpd restart

#/etc/init.d/apache restart
sun solaris
bin/ ./apachectl restart

大体上差不多是这样的……


2.4 对mod_evasive测试验证 ;

防DDOS的模块做好后,我们可以要验证,可以用Apache 自带的ab工具,系统默认安装在/usr/sbin目录中;比如;

#/usr/sbin/ab -n 1000 -c 50 http://www.google.com:80/

注:上面的例子的意思是,如果您的服务器是google的WEB服务器,我们要发送数据请求包,总共1000个,每次并发50个;

另外一个测试工具就是mod_evasive的解压包的目录中,有个test.pl ,你可以修改IP地址,然后用

#perl test.pl
如果是学校的服务器,可以使用./test.pl ,如果是本机测试,test.pl文件里默认的为127.0.0.1

是不是有效果,请根据 ab工具或 测试脚本出来的结果来查看;结果如下显示:

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

HTTP/1.1 200 OK

#######################################################################

因为我们编译mod_evasive时,用的是默认配置,所以日志被存放在/tmp目录中。如果有DDOS攻击,会在/tmp产生日志。日志的文件是以 dos-开头的;


3、mod_evasive 的高级配置;

如果想更改一些适合自己的参数,有些必要的参数,并不是通过配置文件修改就一下起作用的,我们要修改源码包中的 mod_evasive.c(Apache 1.x用之) 或 mod_evasive20.c (Apache 2.x用之);

#define DEFAULT_HASH_TBL_SIZE   3097ul  // Default hash table size
#define DEFAULT_PAGE_COUNT      2       // Default maximum page hit count per interval
#define DEFAULT_SITE_COUNT      50      // Default maximum site hit count per interval
#define DEFAULT_PAGE_INTERVAL   1       // Default 1 Second page interval
#define DEFAULT_SITE_INTERVAL   1       // Default 1 Second site interval
#define DEFAULT_BLOCKING_PERIOD 10      // Default for Detected IPs; blocked for 10 seconds
#define DEFAULT_LOG_DIR         "/tmp"  // Default temp directory

比如我们改改其中的数字,根据英文很容易理解。比如修改日志存放目录,就把/tmp改成别的目录。如果您不知道放在哪好,还是用默认的吧;

具体的英文解释请看如下描述:

DOSHashTableSize

—————-

The hash table size defines the number of top-level nodes for each child’s

hash table. Increasing this number will provide faster performance by

decreasing the number of iterations required to get to the record, but

consume more memory for table space. You should increase this if you have

a busy web server. The value you specify will automatically be tiered up to

the next prime number in the primes list (see mod_evasive.c for a list

of primes used).

DOSPageCount

————

This is the threshhold for the number of requests for the same page (or URI)

per page interval. Once the threshhold for that interval has been exceeded,

the IP address of the client will be added to the blocking list.

DOSSiteCount

————

This is the threshhold for the total number of requests for any object by

the same client on the same listener per site interval. Once the threshhold

for that interval has been exceeded, the IP address of the client will be added

to the blocking list.

DOSPageInterval

—————

The interval for the page count threshhold; defaults to 1 second intervals.

DOSSiteInterval

—————

The interval for the site count threshhold; defaults to 1 second intervals.

DOSBlockingPeriod

—————–

The blocking period is the amount of time (in seconds) that a client will be

blocked for if they are added to the blocking list. During this time, all

subsequent requests from the client will result in a 403 (Forbidden) and

the timer being reset (e.g. another 10 seconds). Since the timer is reset

for every subsequent request, it is not necessary to have a long blocking

period; in the event of a DoS attack, this timer will keep getting reset.

########################################################################

如果您在这里更改了参数,不要忘记修改Apache 配置文件中关于mod_evasive 的参数;

如果您想加入一些其它的参数,请查阅源码包中的README,里面有详细说明,大多来说没太大的必要……

这个文件相当重要,如果您想更改某些设置,就要修改这个文件……

ok,基本上这个module的介绍就这里了

How to configure your logfiles and logformat of Apache


The server error log, whose name and location is set by the ErrorLog directive, is the most important log file. This is the place where Apache httpd will send diagnostic information and record any errors that it encounters in processing requests. It is the first place to look when a problem occurs with starting the server or with the operation of the server, since it will often contain details of what went wrong and how to fix it.
The format of the error log is relatively free-form and descriptive. But there is certain information that is contained in most error log entries. For example, here is a typical message.

[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test

Common Log Format

A typical configuration for the access log might look as follows.

LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common

This defines the nickname common and associates it with a particular log format string. The format string consists of percent directives, each of which tell the server to log a particular piece of information. Literal characters may also be placed in the format string and will be copied directly into the log output. The quote character (") must be escaped by placing a backslash before it to prevent it from being interpreted as the end of the format string. The format string may also contain the special control characters “\n” for new-line and “\t” for tab.

The CustomLog directive sets up a new log file using the defined nickname. The filename for the access log is relative to the ServerRoot unless it begins with a slash.

The above configuration will write log entries in a format known as the Common Log Format (CLF). This standard format can be produced by many different web servers and read by many log analysis programs. The log file entries produced in CLF will look something like this:

127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326

Each part of this log entry is described below.

127.0.0.1 (%h)
This is the IP address of the client (remote host) which made the request to the server. If HostnameLookups is set to On, then the server will try to determine the hostname and log it in place of the IP address. However, this configuration is not recommended since it can significantly slow the server. Instead, it is best to use a log post-processor such as logresolve to determine the hostnames. The IP address reported here is not necessarily the address of the machine at which the user is sitting. If a proxy server exists between the user and the server, this address will be the address of the proxy, rather than the originating machine.
- (%l)
The “hyphen” in the output indicates that the requested piece of information is not available. In this case, the information that is not available is the RFC 1413 identity of the client determined by identd on the clients machine. This information is highly unreliable and should almost never be used except on tightly controlled internal networks. Apache httpd will not even attempt to determine this information unless IdentityCheck is set to On.
frank (%u)
This is the userid of the person requesting the document as determined by HTTP authentication. The same value is typically provided to CGI scripts in the REMOTE_USER environment variable. If the status code for the request (see below) is 401, then this value should not be trusted because the user is not yet authenticated. If the document is not password protected, this part will be “-” just like the previous one.
[10/Oct/2000:13:55:36 -0700] (%t)
The time that the request was received. The format is:[day/month/year:hour:minute:second zone]
day = 2*digit
month = 3*letter
year = 4*digit
hour = 2*digit
minute = 2*digit
second = 2*digit
zone = (`+' | `-') 4*digit

It is possible to have the time displayed in another format by specifying %{format}t in the log format string, where format is either as instrftime(3) from the C standard library, or one of the supported special tokens. For details see the mod_log_config format strings.

"GET /apache_pb.gif HTTP/1.0" (\"%r\")
The request line from the client is given in double quotes. The request line contains a great deal of useful information. First, the method used by the client is GET. Second, the client requested the resource /apache_pb.gif, and third, the client used the protocol HTTP/1.0. It is also possible to log one or more parts of the request line independently. For example, the format string “%m %U%q %H” will log the method, path, query-string, and protocol, resulting in exactly the same output as “%r“.
200 (%>s)
This is the status code that the server sends back to the client. This information is very valuable, because it reveals whether the request resulted in a successful response (codes beginning in 2), a redirection (codes beginning in 3), an error caused by the client (codes beginning in 4), or an error in the server (codes beginning in 5). The full list of possible status codes can be found in the HTTP specification (RFC2616 section 10).
2326 (%b)
The last part indicates the size of the object returned to the client, not including the response headers. If no content was returned to the client, this value will be “-“. To log “0” for no content, use %B instead.

Combined Log Format

Another commonly used format string is called the Combined Log Format. It can be used as follows.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
CustomLog log/access_log combined

This format is exactly the same as the Common Log Format, with the addition of two more fields. Each of the additional fields uses the percent-directive %{header}i, where header can be any HTTP request header. The access log under this format will look like:

127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"

The additional fields are:

"http://www.example.com/start.html" (\"%{Referer}i\")
The “Referer” (sic) HTTP request header. This gives the site that the client reports having been referred from. (This should be the page that links to or includes /apache_pb.gif).
"Mozilla/4.08 [en] (Win98; I ;Nav)" (\"%{User-agent}i\")
The User-Agent HTTP request header. This is the identifying information that the client browser reports about itself.

Multiple Access Logs

Multiple access logs can be created simply by specifying multiple CustomLog directives in the configuration file. For example, the following directives will create three access logs. The first contains the basic CLF information, while the second and third contain referer and browser information. The last twoCustomLog lines show how to mimic the effects of the ReferLog and AgentLog directives.

LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common
CustomLog logs/referer_log "%{Referer}i -> %U"
CustomLog logs/agent_log "%{User-agent}i"

This example also shows that it is not necessary to define a nickname with the LogFormat directive. Instead, the log format can be specified directly in theCustomLog directive.


英文标点符号的读法


{ open brace, open curly 左花括号
} close brace, close curly 右花括号
( open parenthesis, open paren 左圆括号
) close parenthesis, close paren 右圆括号
() brakets/ parentheses 括号
[ open bracket 左方括号
] close bracket 右方括号
[] square brackets 方括号
. period, dot 句号,点
| vertical bar, vertical virgule 竖线
& ampersand, and, reference, ref 和,引用
* asterisk, multiply, star, pointer 星号,乘号,星,指针
/ slash, divide, oblique 斜线,斜杠,除号
// slash-slash, comment 双斜线,注释符
# pound 井号
\ backslash, sometimes
escape 反斜线转义符,有时表示转义符或续行符
~ tilde 波浪符
. full stop 句号
, comma 逗号
: colon 冒号
; semicolon 分号
? question mark 问号
! exclamation mark (英式英语) exclamation point (美式英语)
‘ apostrophe 撇号
– hyphen 连字号
— dash 破折号
… dots/ ellipsis 省略号
” single quotation marks 单引号
“” double quotation marks 双引号
‖ parallel 双线号
& ampersand = and
~ swung dash 代字号
§ section; division 分节号
→ arrow 箭号;参见号

Substraction single digits integers


import javax.swing.JOptionPane;

public class abc {

public static void main (String[] args){

int correctNumber = 0;
int questionNumber = 0;

while(questionNumber<10){
int number1 = (int)(Math.random() * 10)+1;
int number2 = (int)(Math.random ()* 10)+1;

if (number1<number2){
int temp = number1;
number1=number2;
number2=temp;
}

String questionA = JOptionPane.showInputDialog("what is the result of "+ number1 + "-"+ number2+"?");
int answer = Integer.parseInt(questionA);

String replystring;
if (number1-number2==answer){
replystring="The answer is correct" ;

correctNumber++;
}
else

replystring="the answer is wrong";

JOptionPane.showMessageDialog( null, replystring);

questionNumber++;

How to use Java Math.random() method


The Math.random() method returns random double numbers in the range >=0.0 to <1.0 . It returns the same result as the Random nextDouble() method (see below).

double x;
x = Math.random(); // assigns random number to x

Usually the range 0.0…0.999999+ isn't what is desired so it's necessary to scale the range by multiplying and translate the values by addition. Finally, an int is commonly desired, so casting is required.

For example, if you need an int int the range 1 to 10, the following code could be used.

int n = (int)(10.0 * Math.random()) + 1;

The multiplication scales the range to 0.0 to 9.9999+, casting it to int to gets it into the integer range 0 to 9 (truncation, not rounding), then addition of 1 translates it into the range 1 to 10.

The java.util.Random class has convenient methods which do this extra work for you, but you have to create a Random object and make sure it's accessible where you need it (sometimes awkward).