2011-02-13 54 views
1

我使用servlet進行簽入,它可以工作。在Java中填寫表單驗證

如何驗證表單填充? 例如,如果用戶名已經註冊,重新將用戶發送到.jsp文件?

對不起,英語不好。

+0

http://stackoverflow.com/tags/servlets/info – BalusC 2011-02-19 13:14:02

回答

2
public void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException { 

    // fetch the username that was sent in the request 
    String username = request.getParameter("username"); 

    // TODO: verify if the username is taken in the database 

    // based on the results set the value 
    request.setAttribute("isUsernameTaken", "true"); 

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/register.jsp"); 

    dispatcher.forward(request, response);  
}