package cn.edu.bit.servlet;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CheckServlet extends HttpServlet {
public String[] usernameList;
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
String username = (String)request.getParameter("username");
String password = (String)request.getParameter("password");
String repassword = (String)request.getParameter("repassword");
String email = (String)request.getParameter("email");
if(this.IsContain(username))
{
request.setAttribute("error.message","您输入的用户名已经存在!");
RequestDispatcher requestDispatcher = request.getRequestDispatcher("error.jsp");
requestDispatcher.forward(request,response);
}else
{
RequestDispatcher requestDispatcher = request.getRequestDispatcher("success.jsp");
requestDispatcher.forward(request,response);
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException
{
doGet(request,response);
}
public void init(ServletConfig config) throws ServletException {
usernameList = new String[]{"Tom","Jerry","Brain"};
}
public boolean IsContain(String param)
{
for(int i = 0; i <usernameList.length;i++)
{
if(usernameList[i].equals(param))
{
return true;
}
else
continue;
}
return false;
}
}