开发者

JSP page to static HTML using Java code

开发者 https://www.devze.com 2023-03-06 08:05 出处:网络
How do I save a dynamic JSP page to a static HTML page using Java code? I want to save JSP out开发者_如何学编程put to an HTML page and save it on the local machine.

How do I save a dynamic JSP page to a static HTML page using Java code?

I want to save JSP out开发者_如何学编程put to an HTML page and save it on the local machine.


How do I save a dynamic JSP page to a static HTML page using Java code?

Once the client receives the JSP page the server has already performed all the "dynamic stuff". So, just download the web page into for instance a String using, say, the URL class, and write this String out to a file. (You won't get the dynamic parts anyway.)

Related question (possibly even duplicates):

  • How do you Programmatically Download a Webpage in Java
  • How do I save a String to a text file using Java?


Write a Java client application that does something like this...

URL yahoo = new URL(THE URL OF YOUR JSP PAGE);
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));

String inputLine;
String html;

while ((inputLine = in.readLine()) != null) 
   html += inputLine + "\n";
in.close();

// DO SOMETHING WITH THE HTML STRING
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号