简体   繁体   中英

tracking page request with servlets and jsps

If a user goes on get_appointment.jsp but is redirected, by a servlet, to the login.jsp (as he was not logged in). After successful log in, he should return to the get_appointment.jsp, as the initialization was being done from there.

Now what machanism should be used to track that from which page the request originally came, may be got forwarded to different jsps and servlets and then the user should return to the original (initial page) again.

whats the most common and better way , in general rules. is there any one for the current senarios i explained? there are many, session attributes, url rewriting, global and application, servlet context.

what if user manually changes the address bar and goes to some other place. the session attribute then make him land some time later to some incorrect page.

whats a proper way?.................

for sessions. if iam in verfiycreds.java . is there a way to get the page addres from which the request was sent to verifycred.java (ie login.jsp)?

You could save it in the user's session...

doGet(HttpServletRequest request, HttpServletResponse response) {
    // Could also be doPost(), depending on which you need.
    // Request and response are both abailable there as well.
    ...
    HttpSession session = request.getSession();
    session.setAttribute("referralURI", request.getRequestURI());
    ...
}

You can then retrieve the URI with request.getSession().getAttribute("referralURI") .

If you want to avoid sessions, you could also pass the relevant portion of the URI as a get parameter to the login.

In spring-security, the request is saved at the point, where the request gets intercepted, because it is unauthorized - in the ExceptionTranslationFilter . After successful authentication, the success-handler SavedRequestAwareAuthenticationSuccessHandler / API will be called. This handler redirects to the URL of the request, previsouly stored in the HttpSession by the ExceptionTranslationFilter.

To answer your question, this is a proper way. Look at the way they implemented it, look at the patterns, check out the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM