tags:

views:

2504

answers:

5

I'm tasked with trying creating a site which will create custom HTML templates. The customizations are based-up customized upon user input. I'm currently using tomcat / JSP for the rest of the front end. What I want to do is create the HTML templates in JSP to output conditional HTML code, but instead of display this HTML output to the user, I'd like to save this code to several files (which will then be zipped up 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 (process includes and evaluate variables).

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

Thanks!

A: 

Why not use wget? You could load the pages into a real container and then retrieve the generated pages from the container using wget.

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

Using this option in wget will take a list of URLs from a file and download them for you just as the text would be displayed in the view-src of the browser.

Also wget is available for Windows and Linux.

leeand00
thanks for the idea, I love wget, but it doesn't fit my needs
Roy Rico
@Roy Has to do with the zipping bit doesn't it?
leeand00
@leeand00 not specifically, moreso with the fact that this is a java environment that has to work in multiple environments, and we have windows, mac and linux developers working on the same codebase, so the solution needs to be java based
Roy Rico
+1  A: 

You could have a servlet that calls to the JSP by opening a URLConnection and then reading in the output into a temp file or a buffer. It would then zip it and write the zip out.

sblundy
+3  A: 

Here is an idea. Create a servlet to accept the input from the user, from the servlet use java.net.HttpURLConnection to pass the input to the JSP page and to 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 zip all the files you pull and return it to the user

Mark Robinson
+1  A: 

I'm really not sure I understand your question, but I will take a stab at it. Why not create a servlet and have it call your jsp file using the following:


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

Have the jsp show the front end with the form / user inputted values. When the form is completed, submit the form. At which point the jsp will return context to the servlet where you can parse the values, determine which files to create and return to the user. Once you have determined what you want to display to the user, throw it into another jsp and pass the context to that jsp.

You can do this in 2 ways. You can create a different jsp for the different filetypes you wish to return and simply call the proper one. Or You can pass whatever structures / values you want into your jsp by embedding them in the request and then getting them within your jsp. You can use this fact to create a single jsp that based on passed in parameters(embedded within the request) will display the proper information.

If I completely missed the point of your question, feel free to delete this response.

Edit: Either way you will have to embed your values within the request.

kgrad
A: 

You can also try using some of the many light template engines which were designed specifically for such job. That's what I did when I had similar task and never looked back. Check out Velocity for example.

serg