开发者

Servlet POST parameters null

开发者_运维技巧I want a servlet to print the parameters from a html form but in the servlet the request has no parameters.

<form method="post" action="LoginServlet" >
    <input type="text" name="username" id="username" /><br/>
    <input type="text" name="password" /><br/>
    <input type="submit" />
</form>

and the servlet's doPost():

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("POST");

    HttpSession session = request.getSession();
    String redirectUrl;

    Enumeration atributes = request.getAttributeNames();
    while (atributes.hasMoreElements()) {

        System.out.println((String )atributes.nextElement()+ ".");
    }
    String user = (String) request.getAttribute("username");
    String pass = (String) request.getAttribute("password");
    System.out.println("user:" + (String) request.getAttribute("username"));

}

So it doesn't output any parameters and the username parameters is NULL.


These are parameters - use getParameter(String).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜