I am working on websphere with 2 application servers - one for web and one for engine.
I have a servlet running on engine which recieves the type of input and returns the string as response in PrintWriter.
In web module Inside a servlet I need to call the servlet of engine - pass the input and get the response.
I know request.sendRedirect will help me but this redirects the page to the engine.
Could you please suggest me a way by which i can pass input from my web servlet to engine servlet and get the response from engine servlet to web.
Firstly, assuming that you're talking about HTTPServletRequest, there's no method sendRedirect in that interface. Perhaps you meant response.sendRedirect("...")?
Now if you use that, a new request object will be created and any parameters that you received in the current request object will NOT be relayed onto the new request object created as a result of the sendRedirect.
You should probably look into RequestDispatcher.
Also, please make use of the [code] tags when you're posting code. It greatly improves readability of your posted code.
It can't be used to forward requests to another server.
sendRedirect is the way to go
Joined: Feb 22, 2005
My bad :/ Thanks for pointing that out Balu. He's right, you can't make use of RequestDispatcher in this scenario.
In that case, what you've done - establishing a connection using HttpURLConnection seems to be a viable option. So what happens when you try using that technique? Do you face any error while using it?
Joined: Dec 06, 2007
Yes the call doesnt go the other servlet.
My assumptions :
- Is it because the url that is framed is https:??
- There should be a way using response object to establish a connection to the other servlet in the same WAS box but different application server and read the data.
Currently the call to the other servlet is not going.
You can try RMI... but still you cannot create a HTTP connection as you are expecting..... i really thinking is their is no option provided in j2ee to connect to a another server and get the response back???