Параметры POST сервлета null - PullRequest
0 голосов
/ 10 июля 2010

Я хочу, чтобы сервлет печатал параметры из html-формы, но в сервлете запрос не имеет параметров.

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

и 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 Ответ

3 голосов
/ 10 июля 2010

Это параметры - используйте getParameter(String).

...