(1)包含有Form表单得页面必须通过一个服务器程序动态生成,服务器程序为每次产生得页面中的form表单都分配一个唯一得随机标识号,并在form表单得一个隐藏域 保存
(2)当用户提交form得时候,负责接受这一请求得服务器程序比较form表单隐藏字段中的标识号与存贮在session中的是否相同,当下列情情况时候,服务器程序将忽略提交请求:
a.当前用户session不存在表单标识
b.用户提交得表单数据并没有标识号字段
c.存贮在当前用户的session中得标识号与表单数据中的不同
tokemProcessor.saveToken(request);
String token=(String)request.getSession().getAttribute(tokemProcessor.FORM_TOKEN_KEY);
%>
<
html
>
<
head
>
<
title
>
用户登陆
</
title
>
</
head
>
<
body
>
<
form
action
="/testServlet"
method
="post"
>
<
input
name
="<%=tokemProcessor.FORM_TOKEN_KEY %>"
value
="<%=token %>"
>
<
input
name
="q"
/>
<
input
type
="submit"
value
="submit"
/>
</
form
>
</
body
>
</
html
>