Capture JSP output, save to file

I am tasked with creating a site that will create custom HTML templates. Settings are configured for user input. I am currently using tomcat / JSP for the rest of the interface. I want to create HTML templates in JSP for outputting conditional HTML code, but instead of displaying this HTML output to the user, I would like to save this code in several files (which will then be sewn and delivered to the user, along with images, css files, js files ) I need to know how to create a fake container that will execute a JSP file (the process includes and evaluates the variables).

I read about using server filters to intercept JSP code output, but I'm not sure it will work, because: a) I need to create several HTML files and b) I need to display different content for the user (i.e. here ur zip file, upload it), not the output of the JSP being processed.

Thanks!

+5
source share
5 answers

Here is an idea. Create a servlet to accept input from the user, from the servlet use java.net.HttpURLConnection to transfer the input to the JSP page and get the result.

URL urlPage = new URL(url);
HttpURLConnection conn = (HttpURLConnection)urlPage.openConnection();
conn.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

//then loop through lines of webpage with br.readLine();

Then in your servlet you can pin all the files that you pull out and return them to the user

+4
source

, JSP, URLConnection, . zip.

+1

, , . jsp , :


    RequestDispatcher d = getServletContext().getRequestDispatcher(jspName);
    d.forward(request, response);

jsp / . , . jsp , , , . , , , jsp jsp.

. jsp , , . /, jsp, , jsp. jsp, ( ) .

, .

: .

+1

wget? , wget.

--input-file=FILE read URLs from file.

Using this parameter in wget, you will get a list of URLs from the file and load them for you in the same way that the text will be displayed in the browser-src viewer window.

Also wget is available for Windows and Linux.

0
source

You can also try using some of the many lightweight template templates that were designed specifically for this kind of work. This is what I did when I had a similar task, and never looked back. For example, Velocity .

0
source

All Articles