Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirecting to the last requested page after valid log in

 
mohammad enamul haque
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Would anyone please be able to help me on the following:

For example, assuming the following scenario:

1) A web application contains a page "secret.html", which is a protected resource, declared to require login. Assume mode is "Form Based Login".

2) User tries to access page "secret.html"

3) then the user is re-directed to "login.jsp", the user needs to fill in "username" and "password" first .

3) then after checking the username/password. If they are valid, it will redirect the user to the originally-requested page ("secret.html").

how can i do this in my project?
[ August 05, 2008: Message edited by: mohammad enamul haque ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "need help" is not useful.

Please go back and change your post to add a more meaningful subject by clicking the .
[ July 30, 2008: Message edited by: Bear Bibeault ]
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mohammad enamul haque welcome to Javaranch
Firstly as suggested by Bear, use a descriptive subject line.

regarding your question, why dont you make secret.jsp instead of secret.html, so that you can check in the JSP if the user accessing it is authenticated.
Another option is container managed security, but I am unsure how it works.


Hope this helps
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really, it would be better to use declarative security, since what you have described is Form Based Authentication (look in the documentation for your container)

This allows you to put member resources (like your file) in a /member/ directory and the container makes sure that people have that role before they are allowed to access the resource. Applying security to each resource is error-prone.
 
kamalkant rajput
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friend,
If you could give me little more detail then it could be helpful for me to help you.Any way if you are using just jsp pages then then give form action to first page and make first page also jsp page. If you are using servlet then redirect the control from servlet to the first page.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are using form based authentication, you just have to name your user name field as j_username and your password field as j_password and the form action as j_security_check. Then you server will automatically manage redirecting to login.jsp for login. After successfull login the user will automatically be redirected to secret.html. Here's the code for login.jsp

This should do it. But this will only work if you have defined form based security for the secret.html file in the deployment descriptor (web.xml) for your web application.
 
mohammad enamul haque
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi AnkitJi Garg,

Thnak you very much for your reply. Could you please tell me how could i make the changes in web.xml??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohammad enamul haque, we are still waiting for you to give this post a better title.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code for Web.xml



I think the tag names are self explanatory. But if you still have problems ask me....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic