What is the way to render jsp file to a string? Is it possible without using frameworks like spring/struts/etc?..
A:
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
2009-09-23 07:08:13
Thank you very much!
Overdose
2009-09-23 07:17:15
A:
You may compile JSP Pages with any JSP Rendering engine, for example Apache Jasper, included in Apache Tomcat.
Alexey Sviridov
2009-09-23 07:08:34
A:
Use MockRunner. This allows you to run JSPs in test cases, for example.
Aaron Digulla
2009-09-23 07:53:11