jsp:include 出现 Bean 错误

发布于 2024-11-07 15:06:06 字数 732 浏览 0 评论 0原文

我有一个页面太长,无法在一个块中处理(try 语句中的代码太长),所以我想切入不同的jsp。但现在我无法在包含的 jsp 中访问我的 bean,并且在任何范围内收到 Cannot find bean: "org.apache.struts.taglib.html.BEAN" 。

我查了一下互联网,发现只有一个页面谈论它,它说我的操作定义不能是页面范围,而我的范围现在是请求。

下面是我的 page1.jsp 的示例

<html:form action="editFooBarAction">
  <jsp:include page=page2.jsp/>
</html:form>

page2.jsp 包含一些 html: 标记和表单 bean 的使用。

这是我的操作的定义

<action
  path="/edit*"
  type="com.sham.web.action.{1}Action"
  name="{1}Form"
  scope="request"
  validate="true"
  input="edit.{1}">
  <forward name="edit" path="edit.{1}"/>
  <forward name="view" path="view.{1}"/>
</action>

是否有办法像这样使用 jsp:include ?

I have a page which is too long to process in one block (code too long in try statement) so I wanted to cut into different jsp. But now i can't access my bean in the included jsp and I receive Cannot find bean: "org.apache.struts.taglib.html.BEAN" in any scope.

I looked over the internet and found only one page that talk about it, it says that my action definition must not be of page scope, and my scope is request right now.

Here is a sample of my page1.jsp

<html:form action="editFooBarAction">
  <jsp:include page=page2.jsp/>
</html:form>

page2.jsp contains some html: tags and use of the form bean.

here is the definition of my action

<action
  path="/edit*"
  type="com.sham.web.action.{1}Action"
  name="{1}Form"
  scope="request"
  validate="true"
  input="edit.{1}">
  <forward name="edit" path="edit.{1}"/>
  <forward name="view" path="view.{1}"/>
</action>

Is there anyway to use jsp:include like that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷夜 2024-11-14 15:06:06

jsp:include 元素在执行 JSP 页面时被处理。 include 操作允许您在 JSP 文件中包含静态或动态资源。包含静态资源和动态资源的结果是截然不同的。如果资源是静态的,则其内容将插入到调用的 JSP 文件中。如果资源是动态的,则请求将发送到包含的资源,执行包含的页面,然后结果包含在调用 JSP 页面的响应中。 - [参考]

解决方案:

尝试将包含的页面设为 JSP 片段 (.jspf)。 JSP 片段静态地包含在另一个 JSP 中。而且它们不是自己编译的。

进一步阅读:

The jsp:include element is processed when a JSP page is executed. The include action allows you to include either a static or dynamic resource in a JSP file. The results of including static and dynamic resources are quite different. If the resource is static, its content is inserted into the calling JSP file. If the resource is dynamic, the request is sent to the included resource, the included page is executed, and then the result is included in the response from the calling JSP page. - [reference]

Solution:

Try making your included page a JSP Fragment (.jspf). JSP Fragments are there to be statically included in another JSP. And they are not get compiled on their own.

Further Reading:

通知家属抬走 2024-11-14 15:06:06

尝试将 bean 放入会话范围中......

Try putting the bean in the session scope....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文