views:

24

answers:

2

I want a servlet to print the parameters from a html form but in the servlet the request has no parameters.

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

and the servlet's 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"));

}

So it doesn't output any parameters and the username parameters is NULL.

+1  A: 

These are parameters - use getParameter(String).

McDowell
A: 

Actually I'm seeing the same issue when using getParameter(String) in a standalone servlet based Java server.

I wrote a client in plain HTML and it works perfectly, but when I use a client that is another Java program using Restlet to call the servlet endpoint, all parameters are NULL.

Is there some magic header setting that the servlet is expecting?

Andre
I suggest you to ask that as a new question instead of posting as an answer :) Check the `Ask Question` button at right top.
BalusC