Hi All,

Is there a way to create a HTML file generated in browser in a JSP file?
This same JSP file parsed by server and show up in a browser in HTML form
and also save this HTML form to a HTML file on the server.

The only way I can think of is using a StringBuffer to append all the HTML form data
and save to a file at the end of the JSP file?

Something like

<%
StringBuffer htmlBuffer = new StringBuffer();
htmlBuffer.append("<HTML><HEAD>");
....
%>
......
<table width=100%>
  <tr>
  <td>Test This Data</td>
  </tr>
</table>
<%
   htmlBuffer.append<"\n<table width=100%>")
   .append("\n<tr>")
   .append("\n<td>Test This Data</td>")
   .append("\n<\tr>")
   .append("\n</table>");
%>

And eventually save this StringBuffer to a file.

I was wondering if there is any easier way.
I'd really appreciate it if anyone can shed some light.

thanks in advance.

-Tian

Recommended Answers

All 3 Replies

JSPs are meant for creating static HTML pages with dynamic content. So you don't need StringBuffer.append(?).. All you need is calling JSP tags and scriptlets and saving the file with .jsp extn.

You can directly write html code in a jsp file.JSP out object is use for that purpose .

out.println("<html>");
 out.println("<body><p>");
 out.println("</p></body>");
 out.println("</html>");

Even if you do write code that create a file with the .jsp extension and save it at the server, what would be its use. You would still need to call it and display it to browser.
Even if you create a dynamic link based on the name of the .jsp file that you programaticaly created there is no practical use for such technique.

What are you trying to accomplish?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.