如何从Servlet调用JSP而不影响输出?
我既不是服务器端编程专家,也不是 Java-EE 专家,我一直在寻找如何完成一项非常简单的任务。我什至不知道如何表达这一点,这使得在谷歌上搜索或在 API 中搜索变得困难。
我有一个 Servlet,该 Servlet 正在调用两个不同的 JSP 页面。其中之一是实际输出,带有 html 代码。 AFAIU 这可以通过这句话来完成 request.getRequestDispatcher("my_jsp_page.jsp").forward(request, response);
但是我想调用的第二个 JSP 不应该是响应的一部分/输出。它只是一个生成的 vCard(文本文件)。所以我想我不能使用前一句也不能使用 include
方法,因为 include
会影响输出,对吗?
任何提示或建议将不胜感激。
问候。
PD:可能是我没有正确表达自己的意思。 jsp-html 文件的输出显示在浏览器上,也就是说,这是实际的响应。 jsp-vcard 文件的输出是一个文本可下载文件,这就是为什么我认为它不应该包含在输出中。
I'm not an expert in Server-side programming nor Java-EE, and I've been looking how to achieve a pretty simple task. I'm not even sure how to express this, which made difficult to google it or to search in the API.
I have one Servlet, This Servlet is calling two different JSP pages. One of them is going to be the actual output, with html code. AFAIU this can be done by this sentence request.getRequestDispatcher("my_jsp_page.jsp").forward(request, response);
But the second JSP I want to call shouldn't be a part of the response/output. It's just a generated vCard (text file). So I think I can't use the previous sentence nor the include
method, cause the include
would affect the output, am I right?
Any tip or suggestion is greatly appreciated.
Regards.
PD: Probably I didn't express myself correctly. The output of the jsp-html file is displayed on the browser, it's to say, it's the actual response. The output of the jsp-vcard file is a text downloable file, that's why I think it shouldn't be included in the output.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来,必须生成文本文件并将其存储在服务器上,并在后续请求中提供服务。
使用普通
FileOutputStream
存储文件,最好将其存储在 Web 应用程序之外的位置。As it seems, the text file has to be generated and stored on the server, and be served in a subsequent request.
Store the file with a normal
FileOutputStream
, preferably in a location outside the webapp.只要包含的 jsp 文件不向响应写入任何内容,您就可以包含它。它将被执行(在您的示例中生成一个文本文件),但不会影响您的最终输出。
As long as the included jsp file dont write anything to the response, you can include it. It will be executed(in your example generate a text file) but will not affect your final output.
您可以读取文本文件并将其设置为响应。并设置
You can read text file and set it in response. and set