1

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

I want to save JSP output to an HTML page and save it on the local machine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ruchi
  • 5,032
  • 13
  • 59
  • 84

2 Answers2

2

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):

Community
  • 1
  • 1
aioobe
  • 413,195
  • 112
  • 811
  • 826
1

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
gshauger
  • 747
  • 4
  • 16