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.

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

  }
}


0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact