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

interceptors

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi gurus,

I have a hopefully quick question about interceptors. My example:

www.mysite.com/login.jsp
-user logs in and creates session data for the user, which then redirects to www.mysite.com/welcome.jsp

welcome.jsp has no associated actions. It is a basic jsp which integrates some session data variables.

if a user tries to deep link and access www.mysite.com/welcome.jsp directly without logging in first, what do I need to add into struts.xml to intercept this? I've only seen examples such as:



The above example only intercepts the action, correct? How do I intercept a page redirect?

Thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An S2 application shouldn't ever see a JSP page directly, particularly if you want to use S2 functionality for said JSP pages. Is there any particular reason you need to access a JSP directly?
 
chris locke
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:An S2 application shouldn't ever see a JSP page directly, particularly if you want to use S2 functionality for said JSP pages. Is there any particular reason you need to access a JSP directly?



I'm not sure what you mean by that...

You're saying that the jsp should never be visible to the user? As in, the user should never know that "welcome.jsp" exists due to mapping? Or that S2 apps should never access jsp, period? As in, "<result name="error">Login.jsp</result>" is bad practice?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The former--the second one doesn't make any sense. Accessing a JSP through an action isn't accessing a JSP directly--it's accessing it through an action.
 
chris locke
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh.. sorry. I'm still new to this so I wasn't sure what "direct" jsp access meant.

In my app the jsps aren't visible to the user. For example, the www.mysite.com/login.jsp page is accessed by the user with www.mysite.com/login. The user shouldn't be able to access the jsps directly, however here is my dilemna:

When the user goes to www.mysite.com I want them to automatically get redirected past the login page if valid session data already exists. So, I was advised to create a filter/interceptor that checks for valid session data when trying to access any content page, and redirect to the login page if it failed. My welcome file is currently:



I want it to intercept the access to welcome.jsp (any any other content jsp for that matter) and perform the session check.. I want the login action from the login.jsp page to bypass this interceptor since it creates the session data. Am I going about this all wrong? Is there a better way?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why you need to check the JSP itself.

Actions not requiring the login check should be configured to use an interceptor stack without it, those requiring the check shouldn't. The only JSP that might be accessed directly is a welcome page, which should redirect to an action, which would be covered by the appropriate interceptor stack.
 
chris locke
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I don't know why you need to check the JSP itself.

Actions not requiring the login check should be configured to use an interceptor stack without it, those requiring the check shouldn't. The only JSP that might be accessed directly is a welcome page, which should redirect to an action, which would be covered by the appropriate interceptor stack.



Hmmm...ok. Well, the first part of what you said makes sense. The 2nd part about redirecting the welcome page to an action, how do I do that?

Thanks :)
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an HTML meta refresh tag.
 
chris locke
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate the help, but you've confused me thoroughly. I'll come back to this later
 
chris locke
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I found a way around this.

If the <welcome-file-list> is pointing to Login.jsp for example, you can add into Login.jsp the following:


I'm not sure if it's good practice to be doing so but if you're trying to call an action from the web.xml file, this works.
reply
    Bookmark Topic Watch Topic
  • New Topic