?
Solved

simulating browser in java application

Posted on 2003-02-19
4
Medium Priority
?
912 Views
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.
0
Comment
Question by:thushara
[X]
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
4 Comments
 
LVL 2

Accepted Solution

by:
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.
0
 
LVL 3

Expert Comment

by:msterjev
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!
0
 

Expert Comment

by:davestubbs
ID: 7986942
you want code........

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

public class URLConnection
{

     public static void main(String[] args)
     {

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

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

               String line;
               while ((line = reader.readLine()) != null)
               {
                    System.out.println(line);
               }
          }
          catch (IOException e)
          {
               System.out.println(e);
          }
     }
}
0
 

Author Comment

by:thushara
ID: 7991275
Thank u very much.
0

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