thushara
asked on
simulating browser in java application
how can I simulate the client browser event in my servlet? My need is while I'm having a session with the client, sending a http request to a different app server(without knowing to the client) and getting it's response back to my servlet and proceed with the client session. Since response.sendRedirect(url) method uses the request via client browser the response is sent back to the client. I don't want this to happen. example code is much appreciated.
thanx in advance.
thanx in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you want code........
import java.io.*;
import java.net.*;
public class URLConnection
{
public static void main(String[] args)
{
try
{
URL url = new URL("https://www.experts-exchange.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
StringBuffer contentsBuffer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.get InputStrea m()));
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
import java.io.*;
import java.net.*;
public class URLConnection
{
public static void main(String[] args)
{
try
{
URL url = new URL("https://www.experts-exchange.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
StringBuffer contentsBuffer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.get
String line;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
ASKER
Thank u very much.
Use HttpURLConnection to the other site.
Set Contet Type of the ServletResponse the same as the HttpURLConnection Content-Type.
Read everything from the HttpURLConnection'r input stream and write it to the ServletResponse's output stream!
I think you can this yourself!