This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Posting request to other domain using jsp

 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use HttpServletResponse.sendRedirect() method.
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

Isn't that what Web Services are for?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic