一个servlet处理来自多个不同页面的请求!

例如有一个用户表,我们要处理 添加,删除 用户以及登录功能

对应的有add.jsp del.jsp login.jsp等

<body>

  <!-- login.jsp -->

    <form action="UserServlet?method=login" method="post" id="login">

        userName:<input type="text" name="userName"/>

        passWord:<input type="password" name="passWord"/>

        submit:<input type="submit" value="submit"/>

    </form>

  </body>

 

 <body>

  <!-- add.jsp -->

    <form action="UserServlet?method=add" method="post" id="add">

        userName:<input type="text" name="userName"/>

        passWord:<input type="password" name="passWord"/>

        name:<input type="text" name="name"/>

        submit:<input type="submit" value="submit"/>

    </form>

  </body>
//UserServlet

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

        String method = request.getParameter("method");

        if(method.equals("login")){

            //处理登录

        }

        else if(method.equals("add")){

            //处理添加

        }

    }

 

你可能感兴趣的:(servlet)