捕获JSP输出,保存到文件 [英] Capture JSP output, save to file

查看:122
本文介绍了捕获JSP输出,保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是尝试创建一个可以创建自定义HTML模板的网站。自定义基于用户输入自定义。我目前正在使用tomcat / JSP作为前端的其余部分。我想要做的是在JSP中创建HTML模板以输出条件HTML代码,但我不想将此HTML输出显示给用户,我想将此代码保存到多个文件中(然后将其压缩并传送到用户,以及图像,css文件,js文件)。我需要知道如何创建一个执行JSP文件的假容器(进程包含和评估变量)。

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

我读到了使用服务器过滤器拦截JSP代码的输出,但我不确定这是否可行,因为a)我需要创建几个HTML文件和b)我需要向用户显示不同的内容(即这里是你的zip文件,下载它)而不是正在处理的JSP的输出。

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.

谢谢!

推荐答案

这是一个想法。创建一个servlet来接受来自用户的输入,从servlet使用java.net.HttpURLConnection将输入传递给JSP页面并获取结果。

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();

然后在您的servlet中,您可以压缩您提取的所有文件并将其返回给用户

Then in your servlet you can zip all the files you pull and return it to the user

这篇关于捕获JSP输出,保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆