I had a question about Java Servlets.
lets say I am on a servlet webpage, ‘somePage’. I want to log in (using another servlet, ‘login’ servlet). So i click on the log-in link on the ‘somePage’ and get redirected to the ‘login’ page. I type in my name and password and they are both correct. the login page has successfully logged me in.
(now asking about coding for the ‘login’ servlet) How do I code the ‘login’ page so that it will redirect the successfully logged in person back to the, ‘somePage’ webpage?
Main Question: How does the login page know the page which initially redirected to it is the ‘somePage’ page?
I have checed out a lot of the request parameters, but non tell me, yes, you were directed from page, ‘somePage’. These are the the paramater i have looked at:
String authType = request.getAuthType();
String pathInfo = request.getPathInfo();
String pathTranslated = request.getPathTranslated();
String getUserName = request.getRemoteUser();
String remoteAdd = request.getRemoteAddr();
String uriString = request.getRequestURI();
String sessionID = request.getRequestedSessionId();
String serverName = request.getServerName();
Integer serverPort = request.getServerPort();
String servletPath = request.getServletPath();
I know some of these are obvously not going to give me the answer I am looking for, but I figure one of the HttpServletRequest parameters has got to tell the login page who asked for it to be displayed. Any help would be greatly appreciated. I’m going to continue my search for the answer. I’ve tried to search for this question, but haven’t found an answer.
There are different ways of doing this. One way is to have your login page support a
continueCGI parameter that gives the URL to which to redirect after the login is successful. Another way to do this is to use the “Referer” header that was passed to the login page, and redirect to that URL.For the former, you can use ServletRequest.getParameterMap() to get the CGI arguments and determine if there is a CGI parameter named
continue(or whatever name you choose to give to that CGI parameter); for the latter, you can use HttpServletRequest.getHeader() to get the “Referer” header.