Initiate request from java class

Hello

I got a peculiar question

My web container contains the following

a JSP page page1.jsp

second JSP pagepage2.jsp

A servletPushPage

A java classContactServlet

What I want to achieve is when browser is displaying page1.jsp. The ContactSevlet.java class calls the servlet PushPage which redirects to page2.jsp

I am able to successfully load the servlet from ContactServlet.java since I am able to print the response(the contents of page2.jsp) on to console.

But the page2.jsp does not display on the browser, it still displays page1.jsp after servlet completes its function.

Any idea how can I make the page2.jsp to display on the browser?

In other words i should make the Servlet feel like the request has come from page1.jsp for page2.jsp.

The code for servlet and java class are below

package testpackage;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletContext;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* Servlet implementation class for Servlet: PushPage

*

*/

publicclass PushPageextends javax.servlet.http.HttpServletimplements javax.servlet.Servlet{

public PushPage(){

super();

}

protectedvoid processAll(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

response.sendRedirect("http://localhost/rimpush/page2.jsp");

}

protectedvoid doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

processAll( request, response);

}

protectedvoid doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

processAll( request, response);

}

}

/*Java class*/

package testpackage;

import java.io.*;

import java.net.*;

import javax.servlet.http.HttpServletRequest;

publicclass ContactServlet{

public ContactServlet(){

}

publicstaticvoid main( String [] args ){

/*Call the servlet PushPage*/

try{

URL url =new URL("http://localhost/rimpush/PushPage");

URLConnection conn = url.openConnection();

conn.setDoOutput(true);

}

catch ( MalformedURLException ex ){

// a real program would need to handle this exception

}

catch ( IOException ex ){

// a real program would need to handle this exception

}

}

}

Any idea would be gracefully appreciated

Thank you.

[4837 byte] By [m_kka] at [2007-11-26 18:24:19]
# 1
Its the Servlet that calls PushPage. The pushPage's output goes back to the Servlet which has to read it and then write the same to the browser is that's what is desired.ram.
Madathil_Prasada at 2007-7-9 5:58:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> Its the Servlet that calls PushPage.

Its the java class(ContactServlet) which calls PushPage servlet

>The pushPage's

> output goes back to the Servlet which has to read it

> and then write the same to the browser is that's what

> is desired.

>

> ram.

The output of PushPage has to be displayed on the browser

m_kka at 2007-7-9 5:58:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
no one has got a clue?
m_kka at 2007-7-9 5:58:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Your ContactServlet program does makes a request to the "PushPage" servlet independant of the browser. In fact you may as well have just opened up a new browser window - it is the same effect.

In most cases the only way you can put a new page in the browser is if the browser requests it. So if you want something to be loaded into the browser with page1.jsp displayed in it, then that browser needs to make a request to the server.

The standard way of doing this is to either use a meta-refresh tag on the page, or a javascript window.setTimeout.

If you want a "push" technology, you might take a look at [url http://www.pushlets.com] pushlets [/url]. I haven't actually used them, but they might be applicable in this case.

Cheers,

evnafets

evnafetsa at 2007-7-9 5:58:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...