This question already has an answer here:
- Execute JSP directly from Java 4 answers
What is the way to render jsp file to a string? Is it possible without using frameworks like spring/struts/etc?..
This question already has an answer here:
What is the way to render jsp file to a string? Is it possible without using frameworks like spring/struts/etc?..
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])); } }
You may compile JSP Pages with any JSP Rendering engine, for example Apache Jasper, included in Apache Tomcat.
Use MockRunner. This allows you to run JSPs in test cases, for example.