我希望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。