将JSP文件包含在Java中 [英] Include JSP file with Java

查看:90
本文介绍了将JSP文件包含在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以在jsp中包括和包含外部文件,例如:

I know that including and external file in jsp can be done with something like this:

<%@ include file="banner.jsp" %>

但是有没有办法在java类/对象中做到这一点?

But is there a way of doing this inside a java class/object?

推荐答案

您可以通过

You can do it inside a servlet (or any class having access to the current request), via the RequestDispatcher:

request.getRequestDispatcher("/banner.jsp").include(request, response);

请注意,您几乎不需要这样做.这意味着您正在从servlet输出视图内容,并且应该主要在jsp中完成.

Note that you should rarely need to do this. It would mean that you are outputting view content from a servlet, and you should do that mainly in a jsp.

这篇关于将JSP文件包含在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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