我想要一个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>
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"));
}
所以它不输出任何参数,用户名参数为空。