开发者

Form filling validation in Java

开发者 https://www.devze.com 2023-02-10 00:34 出处:网络
I do check in with a servlet, it works. How validation of form filling?开发者_开发知识库 For example, re-send the user to .jsp-file, if a username is already registered?

I do check in with a servlet, it works.

How validation of form filling?开发者_开发知识库 For example, re-send the user to .jsp-file, if a username is already registered?

Sorry for bad english.


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);      
}
0

精彩评论

暂无评论...
验证码 换一张
取 消