?
Solved

struts: forwarding to different application

Posted on 2005-04-15
13
Medium Priority
?
455 Views
Last Modified: 2012-05-07
I have a following element in my struts-config.xml:

            <action path="/actions/createUpdateRfq"      scope="session" input="/jsp/BuyerQueue.jsp" name="buyerQueueFormBean" type="com.talisen.lbwebpo.action.CreateUpdateRfqAction">
                  <forward name="success" path="/jsp/CreateUpdateRFQPlaceHolder.jsp"
                        contextRelative="false" />
            </action>

What if, instead of CreateUpdateRFQPlaceHolder.jsp, I wanted to forward to jsp in a different application on the same server.  How would I do that?
0
Comment
Question by:aturetsky
  • 7
  • 6
13 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13790544
Try:

<forward name="success" path="http://yourhost/yourOtherApp/jsp/CreateUpdateRFQPlaceHolder.jsp"  redirect="true" />

This will clear the request context and your will have no access to the session object but I suppose that is what you want?
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13790599
Thanks.  Well, what if I do want to pass a couple of parameters in the request?  How do I prevent the request context from being cleared?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13790770
>>How do I prevent the request context from being cleared?

You can't with a redirect but you may be able to add some request parameters so that the url you generate becomes
"http://yourhost/yourOtherApp/jsp/CreateUpdateRFQPlaceHolder.jsp?param1=1¶m2=1234
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Expert Comment

by:bloodredsun
ID: 13790784
Along the lines of:

    ActionForward forward = mapping.findForward("success");
    StringBuffer bf = new StringBuffer(forward.getPath());
    bf.append("?param1=1&param2=1234") ;//add parameters here
    return new ActionForward(bf.toString(),false);
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13801903
is there a way to post those parameters instead of having them exposed in the url?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13802021
yes, you just have some hidden form fields and use the onclick javascript handler to submit the form fields that you want using a POST request rather than a GET.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13802072
I am confused.  Do you mean using the struts action or not using the struts action?  I thought based on what you wrote above if I use the action, i will lose the parameters stored in request context.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13802473
Yes, you will lose any parameters or attributes stored in the request object/context but what you are doing here is transferring the information into the new context by adding it to the new request.

here's a basic example of transferring information across web applications (using GET which makes it obvious as it's encoded in the URL, you could equally do it with hidden form fields and a POST request)

at url: http://www.myhostOne.com/bert/page.jsp
<jsp code>
<%
String name="bert" ;
%>
<a href=" http://www.myhostTwo.com/ernie/page.jsp?name=<%=name%>">Click here to transfer to ernies web app </a>
</jsp code>

which becomes

<html code>
<a href=" http://www.myhostTwo.com/ernie/page.jsp?name=bert">Click here to transfer to ernies web app </a>
</html code>

if we click on that link we go to: http://www.myhostTwo.com/ernie/page.jsp?name=bert

where the page code says:

<jsp code>
Welcome, you've come from <%=request.getParameter("name")%>'s webapp.
</jsp code>

which  becomes:

<html code>
Welcome, you've come from bert's webapp.
</html code>

So you can see how we can transfer information across the 2 webapps even though the orignal request was destoyed when we changed to a different webapp on a different server.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13802558
well, that I understand if I am doing it in the get and putting params in the url.  But for your suggestion of using hidden form fields - are you suggesting I still using the struts action?  If so, how?
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13802613
>>  But for your suggestion of using hidden form fields - are you suggesting I still using the struts action

Sorry, I didn't make myself clear. Yes, you can use POSTs and hidden fields but No, you cannot use them via a struts actionFormward, you would have to use them outside of the Struts Framework.

I've told you how to forward to a different application and also given you a solution on how to pass information via  parameters across different webapps. Can I ask why you are trying to forward to a different application, what are you trying to achieve?
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13802642
well, that other app contains a servlet that does the processing that I need, I just need to pass it a parameter consisting of a string array.

the reason I wanted to keep struts "in the loop" is because of the validation that needs to happen before it goes to that page, but I guess I can just handle validation with regular javascript.
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 2000 total points
ID: 13802723
>> well, that other app contains a servlet that does the processing that I need

This is dangerous as you leave yourself open to spoofing attacks. It would be much better to get this servlet into your own webapp but I'm sure you know that. I did a similar thing once with a worldpay/e-commerce site and while nothing bad happened, there wree still a couple of issues that weren't  good.

If you're going to use a POST then you'll have to use something outside of struts as you'll be kind off short circuiting the MVC architecture by doing what you're doing. If you're going to use a GET then you could encrypt the query string and/or add a checksum hash to make sure that no one else has altered the values.
0
 
LVL 1

Author Comment

by:aturetsky
ID: 13828966
Good point, thanks.  BTW, the other question if different as it involves passing stuff to perl app.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I came across an unsolved Outlook issue and here is my solution.
Currently, there is an issue with being able to copy values from an external application to a dropdown list in Project Web Access (PWA).  The standard copy and paste methods don't seem to work properly. Here is a way to accomplish this task to s…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question