Servlet POST参数为null

时间:2010-07-10 16:19:57

标签: forms servlets null parameters

我希望servlet从html表单中打印参数,但在servlet中请求没有参数。

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

和servlet的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"));

}

因此它不输出任何参数,用户名参数为NULL。

1 个答案:

答案 0 :(得分:3)

这些是参数 - 使用getParameter(String)