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
Best wishes,
tony wang
Greenhorn
Joined: Apr 13, 2002
Posts: 14
posted
0
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.
SCJP,SCWCD
Sam Cala
Ranch Hand
Joined: Jan 03, 2001
Posts: 147
posted
0
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 ]
Manohar Karamballi
Ranch Hand
Joined: Jul 17, 2001
Posts: 227
posted
0
Hai,,,
Why don't u use request.setAtribute to pass parameters? Rgds Manohar
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
Joined: Jul 17, 2001
Posts: 227
posted
0
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
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
Joined: Jan 03, 2001
Posts: 147
posted
0
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
Joined: Apr 13, 2002
Posts: 14
posted
0
Hi, What about using external storage?
Sam Cala
Ranch Hand
Joined: Jan 03, 2001
Posts: 147
posted
0
couldn't get you Tony, Pls. explain Pradeep, if you could also explain abt. encrypting parameters ??
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
Joined: Jan 03, 2001
Posts: 147
posted
0
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!!
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!!