7

What is the way to render jsp file to a string? Is it possible without using frameworks like spring/struts/etc?..

Overdose
  • 1,470
  • 3
  • 16
  • 29
  • See also http://stackoverflow.com/questions/1152786/looking-for-a-capturing-impl-of-httpservletresponsewrapper – skaffman Sep 23 '09 at 07:13

3 Answers3

0

If you want to stream any webpage may it be a JSP or any other web page, you can use the method below.

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

public class c {

   public String getHTML(String urlToRead) {
      URL url;
      HttpURLConnection conn;
      BufferedReader rd;
      String line;
      String result = "";
      try {
         url = new URL(urlToRead);
         conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
         rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((line = rd.readLine()) != null) {
            result += line;
         }
         rd.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return result;
   }

   public static void main(String args[])
   {
     c c = new c();
     System.out.println(c.getHTML(args[0]));
   }
}

Kalpak
  • 3,510
  • 4
  • 22
  • 21
0

You may compile JSP Pages with any JSP Rendering engine, for example Apache Jasper, included in Apache Tomcat.

Alexey Sviridov
  • 3,360
  • 28
  • 33
0

Use MockRunner. This allows you to run JSPs in test cases, for example.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820