• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

forwarding request to some other server

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Jsp file need to forward a request to another servlet which is located in another Web Application on another machine. How can I do that? If I also want to add more parameters to the original request from the jsp file, what should I do?
I agree I can use response.sendRedirect("fullUrlHere");
and in the fullURLHere are link to your other server, servlet and send parameters using a GET with ?name=value&name=value etc.
But I'm sorry to mention that I dont want to display the querystring while redirecting. So is there anyway I can forward/redirect a request to other server using POST method. ?
Pls. suggest
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you can set an init-para to the servlet of the redirecting app, from DD. Then retrieve it. By this way, no query string is necessarily passed.
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But parameter values are not known to me in advcance so that I can set an init-param in DD :-)
Suggest me a way out
[ April 22, 2002: Message edited by: Sam Cala ]
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,,,

Why don't u use request.setAtribute to pass parameters?
Rgds
Manohar
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u use sendRedirect method then all the original parameters are lost.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What comes to my mind:
1. You can set the action of the form in a javascript function and place the same in a .js file. The function should be called on form submit or onclick of the button. Also use the post method rather the get - your query string will not be displayed.
2. You can hide the url using a frame.
3. You can have an intermediate servlet on the server to which you simply pass an paramater depending on which it can decide which servlet it should next forward to. The final servlet name can be hardcoded in this intermediate servlet, kept in some properties or an xml file.
I think this should help you to pass the request to a servlet of your choice.
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,,
sendRedirect looses all info regarding previous info..so setting parameters in request is of no use..
Instead we can use session but session will be overloaed..
There may be a better alternative..
Rgds
Manohar
 
Pradeep bhatt
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Encrypt the parameters and send
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.setAttribute wont work since sendRedirect will lost all the request parameters. And I cant use jsp:forward too since I want to redirect a request to a source in another server. Also I dont want to say res.sendRedirect("fulURLHere") using GET ?? I think I'm still there where I started, pls. help...
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sessions too wont work since we woint be able to access the session created from the first server(from where the request is being redirected) in another server. (Pls. correct me if I'm wrong)
 
tony wang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What about using external storage?
 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
couldn't get you Tony, Pls. explain
Pradeep, if you could also explain abt. encrypting parameters ??
 
Pradeep bhatt
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Encrypt ur parameter name and values
for e.g. url?name1=value1&name2=value2
after encryption
url?encryptedname1=encryptedvalue1&encryptedname2=encryptedvalue2.
But be careful here the encrypted output should not contain '&','=' and some characters..Not sure about this otherwise it may not be syntically correct or u may read the wrong value. Just check this out!
At the other servlet, get all parametnames and their values. Then decrypt both the names and values.
Hope this helps.I don't know which encryption algo may help u. Hope this helps.

Originally posted by Sam Cala:
couldn't get you Tony, Pls. explain
Pradeep, if you could also explain abt. encrypting parameters ??

 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I knew, Pradeep, you were talking abt. encryption of paratmeters and sending. But what I wanted to know was how to encrypt and sending the same to the other server ? Will need to check up !
Or guys, do contribute if some other solution is feasible!!
 
Pradeep bhatt
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Append the encrypted name/value pairs to the URL string passed to the sendRedirect () method.
To encrypt u need some encryption algorithm or u could come up with ur own algo. Good Luck!
-----------------------------------------

Originally posted by Sam Cala:
I knew, Pradeep, you were talking abt. encryption of paratmeters and sending. But what I wanted to know was how to encrypt and sending the same to the other server ? Will need to check up !
Or guys, do contribute if some other solution is feasible!!

 
Pradeep bhatt
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess Tony means database...

Originally posted by tony wang:
Hi,
What about using external storage?

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic