• 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

Struts: how to return to previous page after login

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

The are some pages on my website that require the user to be logined in before they can access them.

I have a CheckLogonTag on these secured JSP pages. Currently, when the user trys to access the page, strut's CheckLogonTag redirects the user to the login page. However, I don't know how to return back to the page the user wanted to access (after login).

Pls..HelP!!
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to store the the previous url in session (get the path from the request object) and return the forward for the previous url after you login check.

For e.g.

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've gotten myself in a deadlock and I don't know what the solution is.

Here's what I'm doing when a user try's to access a path without logining in:

1) Get url of page and store as "previousPage" (eg: ../web/service/manageAccount.jsp).

2) redirect user to login page

3) forward user request to "previousPage" (../web/service/manageAccount.jsp).

The problem I'm having is that the manageAccount.jsp has to go throw an action class (.do) before it can display the page content.

Here's my struts config:

<action path="/displayAccount" scope="request" type="com.pbWebApp.action.AccountDisplayAction" name="SearchResultForm" validate="false" >
<forward name="DisplayAccount" path="/web/search/manageAccount.jsp" />
</action>


Here's my manageAccount.jsp w/ CheckLogonTag:

<html:html>

<%-- Check if the user is logged in and redirect to logon if not --%>
<app:checkLogon />

<body>
<b>MY FAVORITE<b>
<html:form action="/searchDetails" name="SearchResultForm" type="org.apache.struts.validator.DynaValidatorForm">

<table width="680" height="246" border="0">
<nested:iterate name="SearchResultForm" id="favoriteDto" property="BusinessDetailDTOs" indexId="index">

...

</nested:iterate>

</table>
</html:form>
</body>

<%@ include file="../common/footer.jsp" %>
</html:html>


My question is...if I have the previous page URL, how can I retrieve the action class to retrieve data before displaying the page?

heLP.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in case anyone is still strugling with this... there is how i solved this in Struts2:

1. in the interceptor, before returning a login page result, i remember current action:

2. after a successful login, here is how i return:


however, keep in mind that i don't know if it adheres to best practices or not... because these are my first days with Struts2.
 
Ranch Hand
Posts: 213
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nina,

Personally, I like your solution Very elegant!
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic