2010-07-10 144 views
0

我想要一個servlet從html表單打印參數,但在servlet中請求沒有參數。Servlet POST參數null

<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")); 

} 

所以也沒有任何輸出參數和用戶名參數爲空。

+0

我認爲這是一個不恰當的問題。沒有足夠的聲望來投票。 – 2014-09-07 07:28:18

回答