I have a question about how I might call/invoke a JSP from another Java class (which is not itself a Servlet) using the Servlet/JSP container.
Created Nov 9, 2002
Tomas Zeman You can use URL class to get JSP response via http protocol
public class GetURL
{
public static void main(String[] args) throws Exception
{
URL httpUrl = new URL("http://some_url/index.jsp");
InputStream istream = httpUrl.openStream();
InputStreamReader ir = new InputStreamReader(istream);
BufferedReader reader = new BufferedReader( ir );
StringBuffer buf = new StringBuffer();
int nextChar;
while( (nextChar = reader.read()) != -1 )
{
buf.append( (char)nextChar );
}
reader.close();
System.out.println( buf );
// in buf, you have what JSP page generated
}
}