日期:2014-05-17 浏览次数:20788 次
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
session.setAttribute("tooken", Math.random()+"");
response.sendRedirect(request.getContextPath()+"/a.jsp");
}
<form action="${pageContext.request.contextPath}/servlet/b" method="post">
<input type="text" name="tooken" value="${tooken}">
<input type="submit" value="发送">
</form>
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {//这里加入了延迟
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
String tooken = request.getParameter("tooken");
String tooken_session = (String)request.getSession().getAttribute("tooken");
System.out.println("request的tooken---------"+tooken);
System.out.println("session的tooken---------"+tooken_session);
if(tooken_session.equals(tooken)){
request.getSession().removeAttribute("tooken");
}
}