Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I use getRemoteUser()  RSS feed

Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code right now:
import javax.servlet.*;
import javax.servlet.http.*;
public class AuthorizationSnoop extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
PrintWriter out=res.getWriter();

out.println("<html><head><title>Authorization snoop</title></head><body>");
out.println("<h1>This is a password protected resource</h1>");
out.println("user name: " + req.getRemoteUser());
out.println("authorization type: " + req.getAuthType());
}// end doGet

}// end class
The output gives values of null for both getRemoteUser() and getAuthType() also. Which front end application could I use for this servlet? I would like to test a username and then see what getRemoteUser() would return. Should I use forms in HTML page? In that case I would have to pass parameters, but getRemoteUser() does not accept parameters.
How could I use getRemoteUser() and get a value other than null?
Thanks in advance.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!