simulating browser in java application

Posted on 2003-02-19
Medium Priority
Last Modified: 2007-12-19
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.
Question by:thushara
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

functionpointer earned 150 total points
ID: 7985679
why dont you just proxy the request for the client? just connect to the resource and write back directly to the ServetOutputStream.

Expert Comment

ID: 7986147
This is simple:

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!

Expert Comment

ID: 7986942
you want code........

import java.io.*;
import java.net.*;

public class URLConnection

     public static void main(String[] args)

               URL url = new URL("http://www.experts-exchange.com");
               HttpURLConnection conn = (HttpURLConnection) url.openConnection();

               StringBuffer contentsBuffer = new StringBuffer();
               BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

               String line;
               while ((line = reader.readLine()) != null)
          catch (IOException e)

Author Comment

ID: 7991275
Thank u very much.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question