代码之家  ›  专栏  ›  技术社区  ›  AdrianS

Servlet POST参数为空

  •  0
  • AdrianS  · 技术社区  · 15 年前

    我想要一个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"));
    
    }
    

    所以它不输出任何参数,用户名参数为空。

    1 回复  |  直到 15 年前
        1
  •  3
  •   BalusC    12 年前

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