}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
package cn.qust.demo1;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class DoForm
*/
@WebServlet("/DoForm")
public class DoForm extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean b = isTokenValid(request);
if(!b) {
System.out.println("请不要重复提交");
return;
}
request.getSession().removeAttribute("token");
System.out.println("注册");
}
//判断表单号是否有效,和structs一样
private boolean isTokenValid(HttpServletRequest request) {
String str = request.getParameter("token");
if(str==null) {
return false;
}
String str1 =(String) request.getSession().getAttribute("token");
if(str1==null) {
return false;
}
if(!str.equals(str1)) {
return false;
}
return true;
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}