• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Redirecting to Login Page

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

I need a help in understanding how to solve the below issues.

Consider in a web based application, I am using the doGet Method. My application contains a Login page, Home Page, Profile page.
As it is a get method i can see the parameters in the URL.

So my query is if I am not logged in and if I give the url of my profile page directly it should take me to the Login page, instead of showing the profile page.
How can we achieve this?? If so in how many ways we can achieve this??

Thanks & Regards,
Ravi.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interceptors is one way of doing it..
 
Bhairava Surya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain that with some example.
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What framework are you using for MVC?
 
Bhairava Surya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please its not related to any framework.. consider its normal MVC2
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Configuring web.xml to use servlet security for Home and Profile pages is sufficient for this; no need to use interceptors, filters, or anything else.
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chinna Ravindra wrote:if I am not logged in and if I give the url of my profile page directly it should take me to the Login page, instead of showing the profile page.
How can we achieve this??


In common, when user comes through the login page, we will be keeping a session variable with the value of 'Username' that user entered.
So in the urls/resources (jsp, servlets) we can check for existence of this variable. If the session variable (which is stored in session scope when user inputs the username, password) value is null (can be extended) then we can redirect the user to login page.
Note:
Even though we do the same in servlet and, if the jsp's are kept outside the WEB-INF then they can be accessed directly by hitting the relevant urls. So in this case we need to do the same in jsp's also. Or we can keep it inside the WEB-INF directory.
 
Bhairava Surya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for all you people response.

But, could some one clearly explain me how can i do this using web.xml
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a section on that in the FAQ: http://faq.javaranch.com/java/ServletsFaq#security
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic