• 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

Posting request to other domain using jsp

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use HttpServletResponse.sendRedirect() method.
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP

Isn't that what Web Services are for?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic