• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

how can I redirect user to the last visited page?

 
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Suppose, from one Action class, i called the servlet & then after successfull execution of the servlet, I want to redirect the user to the previous page. Then, what code I need to write?

Another thing, if any annonymous user tries to post topic/reply, then, how can i redirect him to the login page & after successfull authentication, how can I redirect hime to the specified page (just like the jforum.net's forum is working).

Please help. I am working on the JForum 2.7.1

-- Kunal


[originally posted on jforum.net by kunal2383]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally such stuff is done either via the Referer: HTTP tag or by the redirecting servlet using the Request object to supplying a parameter in some way.

E.g., if I go to protected URL x, the security filter may forward the user to the login page via either an internal redirect (using the RequestDispatcher.forward) or an HTTP redirect, (using the response.sendRedirect method).

With the internal method, the Request object is the same as the original and all info, e.g. requestingURL, queryString, and the like, about the original page is there. This can be used to store it either in the session or as a hidden field on the login form. Then the authenticating servlet can use that info to redirect a valid user to the original page.

With the external method, you should be able to use the request.getHeader method to get the referer HTTP header info. Note that while most browsers will supply this info, it's not really required. So, code for a possible null value (e.g., have a default page if it can't be determined). This can be used the same way as the internal forward to be passed on to the authenticating servlet.
[originally posted on jforum.net by monroe]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually,

i am using jforum 2.1.7 and I want to redirect the anonymous user to the login page while he wants to post a message and after successfull authentication, i want the user to redirect to the previous page.

please reply soon.

-- Kunal

[originally posted on jforum.net by kunal2383]
 
Migrated From Jforum.net
Ranch Hand
Posts: 17424
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Postaction might be the place to look. when he figures otu the user is anonymous, throw the necessary information for writing into the session (for instance as new object)... then send a redirect to the login page, and after the login action, check in the session if the object exists, if so, read it, put the actions to the request context and kill the session information ...

I use such a redirection feature when signing a user on for the first time (in SSO environment). If the user had to be created, he will be redirected to the user profile, instead of the forum start page. I do that by adding/replacing the action and module parameter to the request.
[originally posted on jforum.net by Sid]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!