aspose file tools*
The moose likes JSP and the fly likes Posting request to other domain using jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Posting request to other domain using jsp" Watch "Posting request to other domain using jsp" New topic
Author

Posting request to other domain using jsp

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

I have a requirement to POST a request to other domain.

Actually i have a page x.jsp and domain called www.mydomain.com/test.jsp

I have two parameters in x.jsp that needs to be passed to test.jsp in mydomain.com.

i tried using <jsp:forward> to POST this request. It was not possible.

Please let me know if there is any other way to POST the request from one domain to other (cross domain) using JSP/Servlets.

Thanks in advance

Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234
You can use HttpServletResponse.sendRedirect() method.
Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

Thanks for reply.

But can i store request parameters and send to other domain using using POST method

Also, my test.jsp in other domain should use these request parameters

Sony Agrawal
Ranch Hand

Joined: Oct 04, 2009
Posts: 143
I am not sure if this method can point to different domain. But you can try it.. and let me also know about it
Method of ServletContext interface:

ServletContext.getRequestDispatcher(java.lang.String path)
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

@OP

Isn't that what Web Services are for?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
An HTML form can be submitted to any target URL you like; it does not care to which domain the form's action attribute points.


Ping & DNS - my free Android networking tools app
Brij Garg
Ranch Hand

Joined: Apr 29, 2008
Posts: 234

But can i store request parameters and send to other domain using using POST method

Also, my test.jsp in other domain should use these request parameters


sendRedirect() method takes String argument. You can append parameters to this string and then pass this to sendRedirect method
Your string then will be something like ..

Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

You can append parameters to this string and then pass this to sendRedirect method


Yes, i can pass, then it would be passing parameters through query string. Then it is using GET method, right.

I have a requirement that these parameters should not be visible while passing because these are secure parameters
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
Assuming that the web page is served from server A, do you want the flow to be: client -> server A -> server B, or do you want the flow to be: client -> server B? If the former, should the response come from server A or from server B?
Skanda Raman
Ranch Hand

Joined: Mar 21, 2008
Posts: 205

Initially the client would access server A-here all the information will be populated in request and this request should be POSTED to server B for further processing. Server B is a third party domain which would validate the information and they would take care of rest of the updates which i would not have the control.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42631
    
  65
So the response should come from server B? That's possible only if you use a client-side redirect - which is a GET, and thus all parameters are visible.

Server A could make web service call to server B to send all the data, and then send a client-side redirect to server B to the browser with nothing but a cryptologically secure ID as parameter (so that server B knows which data to access for this client).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Posting request to other domain using jsp