0

after login I want user to redirect to same webpage how to do that.

Is there any way to send page url to server. So that server can know from which page request has came.

Is there a way to send information to server other than input fields in html from client to server.

1

2 Answers 2

0

You can save the current page to the session in each page, for every page but the login page. Then after login redirect to the value of the current page parameter from the session if one exists, and to the index if it doesn't.

In each page:

session.setAttribute("currentpage", pagename);

In the login code:

String pagename = (String)session.getAttribute("currentpage");
if(pagename == null)
{
    pagename = "index.jsp";
}
response.sendRedirect(pagename);
1
  • @Syed Zeeshan Ali, In JSP you do NOT need to doHttpSession session = request.getSession(); The session variable is already set for you. In a servlet, however, you would need to do that. Mar 16, 2017 at 17:24
0

you can create a filter and then check for this and redirect

if(session != null && !session.isNew())
    chain.doFilter(request, response);
else
    response.sendRedirect("/myhomepage.jsp");

Another one Interesting Answer is following as:

redirect a page in JSP. You can see in the given example that have been used to the method of response.sendRedirect() through which the server sends the response to the client browser, from where the next request comes and it displays that url correctly. You can also redirect the jsp page in a jsp.

Here is the code of redirect.jsp

<html>
<%
String redirectURL = "http://www.stackoverflow.net/";
response.sendRedirect(redirectURL);
%>
</html> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.