• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

how to redirect page

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am making a project and in that i have done like i have 5 pages :

1)a.jsp (Login Page)
2)b.jsp
3)c.jsp
4)d.jsp
5)e.jsp

Now what i have done is like first user have to login then only he can access the remaining pages i.e. b.jsp , c.jsp , d.jsp , e.jsp.

Now like user enters c.jsp directly in the browser and he is not logged in then he will be redirected to a.jsp which is login page.

After successful login i want that user will redirected to the page he entered previously like to c.jsp and not b.jsp which is the next page after successful login.

It should go to c.jsp after successful login but not to b.jsp
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i would advise that u utilize jsp session. here's one example


put this in every page

========================================================================
<% //<!--
//response.setHeader("Cache-Control","no-cache"); //Forces caches to obtain a new copy of the page from the origin server
//response.setHeader("Cache-Control","no-store"); //Directs caches not to store the page under any circumstance
//response.setDateHeader("Expires", 0); //Causes the proxy cache to see the page as "stale"
response.setHeader("Pragma","no-cache"); //HTTP 1.0 backward compatibility
String userNameSess = (String) session.getAttribute("theName");
String urlR = request.getRequestURI();//saves the url that the user logs in but yet validated by the system

if (null == userNameSess) {
request.setAttribute("Error", "Session has ended. Please login.");//also applies to unvalidate user
request.setAttribute("url",urlR);//set url so that the page loads back to the previous page after re-login
RequestDispatcher rd = request.getRequestDispatcher("loginAgain.jsp");
rd.forward(request, response);
}

========================================================================



and in the login page, u shud have this...

========================================================================
String url = (String) request.getAttribute("url");
input type="hidden" name="url" value="<%=url%>
========================================================================



and finally in the login check page (the page where you posted the login name and password for validation)

========================================================================

String url =request.getParameter ("url");


//and after you have validate the user, do this
response.sendRedirect(url);
=========================================================================

you can combine step 2 and 3 in the same page if you validate the user in the same page.

hope it answer your question
[ February 07, 2006: Message edited by: samart mateo ]
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a servlet filter to check for login credentials and forward to the login page as appropriate. You can also grab the original url from the request and remember it (in the session, or perhaps in hidden elements) so that you can redirect to the original target after login.
 
My pie came with a little toothpic holding up this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic