This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionForward between 2 differnt web_apps

 
Anjali Krishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to forward from 1 web_app to another and then return back to the first app. Before forwarding I store all the data in appsA page in the session.

from web_app A --> I am passing a variable called returnTo
this variable has the URL that the second app needs to return to after processing
from web_app appA to web_app appB
ActionForward :
http://localhost:8080/webapp/web_app/appB/initreadB.do?name=test&returnTo=http://localhost:8080/webapp/appA/initappa.do

In appB after processing is done, will forward to the url in returnTo

I would like to know if this approach is correct?
Thanks,
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your approach is good, but there's one problem you need to solve. Your "returnTo" parameter contains characters that are "unsafe" to pass as a parameter in a URL. You will therefore need to encode it like this:

returnTo = java.net.URLEncoder.encode(returnTo, "UTF-8");

Once encoded, this information can be passed as a parameter in a URL.
 
Anjali Krishnan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the reply ! I will encode and decode as needed.
 
Shilpa Tendulkar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Merrill Higginson:
Your approach is good, but there's one problem you need to solve. Your "returnTo" parameter contains characters that are "unsafe" to pass as a parameter in a URL. You will therefore need to encode it like this:

returnTo = java.net.URLEncoder.encode(returnTo, "UTF-8");

Once encoded, this information can be passed as a parameter in a URL.


Question to Merill: Can "returnTo" variable not be passed as hidden? instead of passing in query string. Which could be the best approach?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, either approach will work as long as the URL is encoded. I tend to favor using the ActionForward approach since the value has to be encoded before it is sent.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic