将jsp的内容包含在servlet中
我有这个 servlet:
public class SaveImage extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
out = response.getWriter();
out.println("<html>");
...
// I want to include here the content of this jsp:
// /WEB-INF/mybox.jsp
// (also, with the full context of the servlet)
...
out.println("</html>");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这样做有问题吗(响应已经提交?),我该怎么做?
I have this servlet:
public class SaveImage extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = null;
try {
out = response.getWriter();
out.println("<html>");
...
// I want to include here the content of this jsp:
// /WEB-INF/mybox.jsp
// (also, with the full context of the servlet)
...
out.println("</html>");
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Is there a problem doing it (response already committed?), how can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但你不应该使用这样的 servlet 来输出 html。只需使用 jsp,使用
或<%@ include file=".." %>
But you should not a servlet for outputting html like that. Just use a jsp, with either
<jsp:include />
or<%@ include file=".." %>
谢谢奥佐,你帮助我让这个已有 2 年历史的待定项目最终成型。谢谢。
实际上,要将tomcat的请求从sun web服务器7重定向到应用程序服务器,由于jsps不直接显示在tomcat中,技术是在app.config中使用passthrough并让tomcat处理请求。
THANKS ozho , YOU HAVE HELPED ME TO give final shape to 2 year old pending project. Thanks.
Actually to redirect the request of tomcat from sun web server 7 to application server, since the jsps are not shown in tomcat directly, technique is to use a passthrough in app.config and let the tomcat handle the requests.