You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by To...@aol.com on 2003/06/24 12:22:17 UTC
Best practices - help
Is there a way to populate a bean on a Server's (I'm using Tomcat) start up
in Struts?
I have a Java bean, say X, which is called and a populated in an Action
Servlet, say myAction. Whenever I start my application and call a JSP layer say,
MyLayer.jsp, which is supposed to iterate this bean using <logic:iterate>,
I get the exception:
org.apache.jasper.JasperException: Cannot find bean X in scope session
-----
-----
However, this exception disappears when I first call the Action Servlet
directly with a call such as http://localhost/myaction.do , followed by a
http://localhost/MyLayer.jsp call.
Apparently the bean has nothing to show when I first call MyLayer.jsp.
Can someone suggest a better approach?
Thanks
Bob
Ps.: the bean, X, get its values from a database.
my struts-config.xml snippet :
---
--
<global-forwards>
<forward name="books" path="/MyLayer.jsp"/>
-------
-------
</global-forwards>
<action-mappings>
<action path="/myaction"
type="com.myController.myAction"
scope="session"
>
<forward name="books" path="/MyLayer.jsp"/>
</action>
</action-mappings>
----
RE: Best practices - help
Posted by Steve Raeburn <st...@ninsky.com>.
You should not access the JSP directly. Always send requests to the Action
which will return an ActionForward to the JSP. In your example you should
always be accessing /myaction.do and never /MyLayer.jsp
You seem to have it set up OK, but there's no need for your global forward
to the JSP.
Steve
> -----Original Message-----
> From: TopBid987654321@aol.com [mailto:TopBid987654321@aol.com]
> Sent: June 24, 2003 3:22 AM
> To: struts-user@jakarta.apache.org
> Subject: Best practices - help
>
>
> Is there a way to populate a bean on a Server's (I'm using
> Tomcat) start up
> in Struts?
>
> I have a Java bean, say X, which is called and a populated in an Action
> Servlet, say myAction. Whenever I start my application and call a
> JSP layer say,
> MyLayer.jsp, which is supposed to iterate this bean using
> <logic:iterate>,
>
> I get the exception:
> org.apache.jasper.JasperException: Cannot find bean X in scope session
> -----
> -----
>
> However, this exception disappears when I first call the Action Servlet
> directly with a call such as http://localhost/myaction.do , followed by a
> http://localhost/MyLayer.jsp call.
>
> Apparently the bean has nothing to show when I first call MyLayer.jsp.
>
> Can someone suggest a better approach?
>
> Thanks
>
> Bob
>
> Ps.: the bean, X, get its values from a database.
>
> my struts-config.xml snippet :
>
> ---
> --
>
> <global-forwards>
> <forward name="books" path="/MyLayer.jsp"/>
> -------
> -------
> </global-forwards>
> <action-mappings>
> <action path="/myaction"
> type="com.myController.myAction"
>
> scope="session"
> >
> <forward name="books" path="/MyLayer.jsp"/>
> </action>
>
> </action-mappings>
> ----
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Best practices - help
Posted by Steve Raeburn <st...@ninsky.com>.
You should not access the JSP directly. Always send requests to the Action
which will return an ActionForward to the JSP. In your example you should
always be accessing /myaction.do and never /MyLayer.jsp
You seem to have it set up OK, but there's no need for your global forward
to the JSP.
Steve
> -----Original Message-----
> From: TopBid987654321@aol.com [mailto:TopBid987654321@aol.com]
> Sent: June 24, 2003 3:22 AM
> To: struts-user@jakarta.apache.org
> Subject: Best practices - help
>
>
> Is there a way to populate a bean on a Server's (I'm using
> Tomcat) start up
> in Struts?
>
> I have a Java bean, say X, which is called and a populated in an Action
> Servlet, say myAction. Whenever I start my application and call a
> JSP layer say,
> MyLayer.jsp, which is supposed to iterate this bean using
> <logic:iterate>,
>
> I get the exception:
> org.apache.jasper.JasperException: Cannot find bean X in scope session
> -----
> -----
>
> However, this exception disappears when I first call the Action Servlet
> directly with a call such as http://localhost/myaction.do , followed by a
> http://localhost/MyLayer.jsp call.
>
> Apparently the bean has nothing to show when I first call MyLayer.jsp.
>
> Can someone suggest a better approach?
>
> Thanks
>
> Bob
>
> Ps.: the bean, X, get its values from a database.
>
> my struts-config.xml snippet :
>
> ---
> --
>
> <global-forwards>
> <forward name="books" path="/MyLayer.jsp"/>
> -------
> -------
> </global-forwards>
> <action-mappings>
> <action path="/myaction"
> type="com.myController.myAction"
>
> scope="session"
> >
> <forward name="books" path="/MyLayer.jsp"/>
> </action>
>
> </action-mappings>
> ----
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org