tags:

views:

43

answers:

3

Hi,

I want to know how can I get the value of the request parameters "j_username" and "j_password"?

After successfully login using form based authentication, I want my servlet to get the value of parameters "j_username" and "j_password", but I'm getting null as the value in both parameters. Could anyone please tell me how can I get the actual value of both paramters?

Servlets class :

package foo;

import javax.servlet.http.*;
import javax.servlet.*;


public class RequestHandler extends HttpServlet
{



 public void doGet(HttpServletRequest request, HttpServletResponse response)
 { 
  try
  {
   String user = request.getParameter("j_username");
   String password = request.getParameter("j_password");
          response.getWriter().println(user+" "+password);
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }



 }
}

output: null null

+1  A: 

You can get the user name through getRemoteUser() or getUserPrincipal(), the latter might also let you get the password after casting to a concrete class, but I doubt it. Your application should not need to know or do anything with the password..

Michael Borgwardt
I actually want to make mail application, and to create session I've to take username and password. Do you know any better approach of doing this?
Dusk
A: 

Try to use

request.getUserPrincipal().getName(); 

to access the username after a successful login instead.

pitpod
+1  A: 

Are you sure you're using GET in your form ? Did you try using doPost instead ?

Valentin Rocher