• 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

document.referrer in struts

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp, with 2 radio buttons,one hidden variable, one submit and one cancel button. This is a static page except that hidden variable value should be populated with previous url where the request has actually came from( ex: like document.referrer.toString() in Javascript). Hidden variable should be populated while loading the jsp page( which is resultant of action class A).
How do I achieve this in struts? Please share your thoughts.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bnraju2000,

First an administrative matter:

The JavaRanch Naming policy requires that your publicly displayed name be a first and last name that is not obviously fictitios. Please change your profile accordingly.

Now for your question:

This would work the same way any Struts form works: Create an ActionForm with a property corresponding to the hidden field, populate it in the action class that forwards to the JSP, then use the html:hidden tag in the jsp to carry forward the value in the JSP.

The only thing you have to watch out for here is that because it's a URL, it's going to contain characters such as "/" and "?" that should be encoded so they can be sent as HTML parameters without causing problems. You should do this encoding and decoding in your Action class. Look at the JavaDoc for java.net.URLEncoder and java.net.URLDecoder for more details on this.
[ March 20, 2008: Message edited by: Merrill Higginson ]
 
Nag Bussa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill for your quick response.

Yes, I created a string property for hidden variable in my form bean.
What I am not sure is how to populate this variable with previous action url in my action class.
Ex: I have 10 action classes - a.do, a1.do,a2.do..a10.do are generating a.jsp, a1.jsp...a10.jsp respectively. a.jsp to a10.jsp contains a link to b.do. This action class(b.do) will generate b.jsp, which has hidden variable called previousUrl. The value of this variable should contain either a.do/a1.do/...a10.do based upon where the user is coming from.

I have tried this approach so far:
1. Created an inline javascript code inside b.jsp


Javascript alert gives me the previous url. But I am not able to populate this value to formbean. When I tried with followinig code, b.jsp generated with empty string instead of the previous url.



I am not sure what I am missing here..? Please advise.
[ March 20, 2008: Message edited by: Nag Bussa ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest setting the URL in the Action class rather than using JavaScript in the JSP. Example:
 
Nag Bussa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This gave me requestedUrl or address in address bar.

I was looking at previous page action url.

In A.jsp, I had to do soemthing like this to get the previous action url:


In BAction class,



This way I am always getting previousActionUrl in my current jsp. But ugly part here is, I had to pass previousActionURL as querystring.

Thanks.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic