You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by john lee <sh...@yahoo.com> on 2013/05/08 18:15:00 UTC
struts 2 session question
for stuts 1, to get session, via the following
session=request.getSession();
session.setAttribute("PERSON", person); /* person is object name */
for struts 2, to get session, via the following
Map session=ActionContext.getContext().getSession();
session.put("PERSON", person); /* person is object name */
question is
for struts2: if i use the following
session.setAttribute("PERSON", person);
then compile to get following error
cannot find symbol
symbol : method setAttribute(java.lang.String,neuco.Person)
location: interface java.util.Map
session.setAttribute
is that means for struts2, when i use session, i have to use session.put, but session.setAttribute is no longer valid?
what is the difference b/w session.put and session.setAttribute?
thanks in advance
john
Re: struts 2 session question
Posted by Dave Newton <da...@gmail.com>.
Personally, I'd use SessionAware and reduce coupling even further.
The docs for both methods should answer this question fairly completely.
The session is exposed as a map in S2, and as a servlet spec artifact in S1.
Dave
On Wed, May 8, 2013 at 12:15 PM, john lee <sh...@yahoo.com> wrote:
>
> for stuts 1, to get session, via the following
>
> session=request.getSession();
> session.setAttribute("PERSON", person); /* person is object name
> */
>
> for struts 2, to get session, via the following
>
> Map session=ActionContext.getContext().getSession();
> session.put("PERSON", person); /* person is object name */
>
> question is
>
> for struts2: if i use the following
> session.setAttribute("PERSON", person);
> then compile to get following error
>
> cannot find symbol
> symbol : method
> setAttribute(java.lang.String,neuco.Person)
> location: interface java.util.Map
> session.setAttribute
>
> is that means for struts2, when i use session, i have to use
> session.put, but session.setAttribute is no longer valid?
> what is the difference b/w session.put and session.setAttribute?
>
> thanks in advance
>
> john
--
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
Re: struts 2 / sitemesh/
Posted by Lukasz Lenart <lu...@apache.org>.
Ken you are right, there are few options how to integrate Sitemesh
with Struts2 and all are documented on the page
http://struts.apache.org/development/2.x/docs/sitemesh-plugin.html
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
2013/5/9 Ken McWilliams <ke...@gmail.com>:
> I know very little about sitemesh integration and am away from my
> development machine but I think the integration guides mention you need to
> use the StrutsPrepareFilter followed by the
> SiteMeshFilter filter followed by the StrutsExecute filter.
>
> Guessing but the SiteMeshFilter might be a custom one designed for struts2
> integration (if there is a struts2-sitemesh-plugin) I'd verify if this is
> the case.
>
>
> On Thu, May 9, 2013 at 12:33 PM, john lee <sh...@yahoo.com> wrote:
>
>>
>>
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
>>
>> <%@ taglib prefix="s" uri="/struts-tags"%>
>>
>> <s:actionerror/>
>> <s:form action="partsearchinput">
>> <s:textfield name="partid" label="partid"/>
>> <s:submit value="search"/>
>> </s:form>
>>
>> the above code works, and verified by
>> http://localhost/ecommerce/partsearchinput.jsp
>>
>> but, after i start to use sitemesh, it has the problem as the following
>>
>> The Struts dispatcher cannot be found. This is usually caused by using
>> Struts tags without the associated filter. Struts tags are only usable when
>> the request has passed through its servlet filter, which initializes the
>> Struts dispatcher needed for this tag. - [unknown location]
>>
>> SEVERE: Unhandled exception occurred whilst decorating page
>> java.lang.RuntimeException: org.apache.jasper.JasperException: An
>> exception occurred processing JSP page /partsearchinput.jsp at line 6
>> 3:
>> 4: <%@ taglib prefix="s" uri="/struts-tags"%>
>> 5:
>> 6: <s:actionerror/>
>> 7: <s:form action="partsearchinput">
>> 8: <s:textfield name="partid" label="partid"/>
>> 9: <s:submit value="search"/>
>>
>>
>>
>> ****************************************************************************
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat web.xml
>>
>> <filter>
>> <filter-name>struts2</filter-name>
>>
>> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
>> </filter>
>> <filter>
>> <filter-name>sitemesh</filter-name>
>> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
>> </filter-class>
>> </filter>
>> <filter-mapping>
>> <filter-name>sitemesh</filter-name>
>> <url-pattern>/*</url-pattern>
>> <dispatcher>FORWARD</dispatcher>
>> <dispatcher>REQUEST</dispatcher>
>> </filter-mapping>
>> **********************************************************************
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/decorators # cat
>> basic-theme.jsp
>>
>> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
>> prefix="decorator" %>
>>
>> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
>> prefix="decorator"%>
>> <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
>>
>> <%@ taglib prefix="s" uri="/struts-tags"%>
>>
>> <body>
>> <table width="100%" height="100%">
>> <tr> <td>
>> <%@ include file="/partsearchinput.jsp"%>
>> </td></tr>
>> <tr> <td>
>> <decorator:body /> <hr />
>> </td></tr>
>> <tr> <td> <h2> <p><font color=blue>Copyright
>> XXXXX</font></p> </h2> </td></tr>
>> </table>
>> </body>
>>
>> *******************************************************************************
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat
>> decorators.xml
>> <decorators defaultdir="/decorators">
>>
>> <decorator name="basic-theme" page="basic-theme.jsp">
>> <pattern>/menu.jsp</pattern>
>> </decorator>
>> </decorators>
>>
>> **********************************************************************************
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
>>
>> <%@ taglib prefix="s" uri="/struts-tags"%>
>> <s:actionerror/>
>> <s:form action="partsearchinput">
>> <s:textfield name="partid" label="partid"/>
>> <s:submit value="search"/>
>> </s:form>
>>
>> ***********************************************************************************
>> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat menu.jsp
>>
>> <body>
>> <h1>test</p>
>> </body>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: struts 2 / sitemesh/
Posted by Ken McWilliams <ke...@gmail.com>.
I know very little about sitemesh integration and am away from my
development machine but I think the integration guides mention you need to
use the StrutsPrepareFilter followed by the
SiteMeshFilter filter followed by the StrutsExecute filter.
Guessing but the SiteMeshFilter might be a custom one designed for struts2
integration (if there is a struts2-sitemesh-plugin) I'd verify if this is
the case.
On Thu, May 9, 2013 at 12:33 PM, john lee <sh...@yahoo.com> wrote:
>
>
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
>
> <%@ taglib prefix="s" uri="/struts-tags"%>
>
> <s:actionerror/>
> <s:form action="partsearchinput">
> <s:textfield name="partid" label="partid"/>
> <s:submit value="search"/>
> </s:form>
>
> the above code works, and verified by
> http://localhost/ecommerce/partsearchinput.jsp
>
> but, after i start to use sitemesh, it has the problem as the following
>
> The Struts dispatcher cannot be found. This is usually caused by using
> Struts tags without the associated filter. Struts tags are only usable when
> the request has passed through its servlet filter, which initializes the
> Struts dispatcher needed for this tag. - [unknown location]
>
> SEVERE: Unhandled exception occurred whilst decorating page
> java.lang.RuntimeException: org.apache.jasper.JasperException: An
> exception occurred processing JSP page /partsearchinput.jsp at line 6
> 3:
> 4: <%@ taglib prefix="s" uri="/struts-tags"%>
> 5:
> 6: <s:actionerror/>
> 7: <s:form action="partsearchinput">
> 8: <s:textfield name="partid" label="partid"/>
> 9: <s:submit value="search"/>
>
>
>
> ****************************************************************************
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat web.xml
>
> <filter>
> <filter-name>struts2</filter-name>
>
> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
> </filter>
> <filter>
> <filter-name>sitemesh</filter-name>
> <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
> </filter-class>
> </filter>
> <filter-mapping>
> <filter-name>sitemesh</filter-name>
> <url-pattern>/*</url-pattern>
> <dispatcher>FORWARD</dispatcher>
> <dispatcher>REQUEST</dispatcher>
> </filter-mapping>
> **********************************************************************
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/decorators # cat
> basic-theme.jsp
>
> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
> prefix="decorator" %>
>
> <%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
> prefix="decorator"%>
> <%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
>
> <%@ taglib prefix="s" uri="/struts-tags"%>
>
> <body>
> <table width="100%" height="100%">
> <tr> <td>
> <%@ include file="/partsearchinput.jsp"%>
> </td></tr>
> <tr> <td>
> <decorator:body /> <hr />
> </td></tr>
> <tr> <td> <h2> <p><font color=blue>Copyright
> XXXXX</font></p> </h2> </td></tr>
> </table>
> </body>
>
> *******************************************************************************
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat
> decorators.xml
> <decorators defaultdir="/decorators">
>
> <decorator name="basic-theme" page="basic-theme.jsp">
> <pattern>/menu.jsp</pattern>
> </decorator>
> </decorators>
>
> **********************************************************************************
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
>
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <s:actionerror/>
> <s:form action="partsearchinput">
> <s:textfield name="partid" label="partid"/>
> <s:submit value="search"/>
> </s:form>
>
> ***********************************************************************************
> alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat menu.jsp
>
> <body>
> <h1>test</p>
> </body>
struts 2 / sitemesh/
Posted by john lee <sh...@yahoo.com>.
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:actionerror/>
<s:form action="partsearchinput">
<s:textfield name="partid" label="partid"/>
<s:submit value="search"/>
</s:form>
the above code works, and verified by http://localhost/ecommerce/partsearchinput.jsp
but, after i start to use sitemesh, it has the problem as the following
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
SEVERE: Unhandled exception occurred whilst decorating page
java.lang.RuntimeException: org.apache.jasper.JasperException: An exception occurred processing JSP page /partsearchinput.jsp at line 6
3:
4: <%@ taglib prefix="s" uri="/struts-tags"%>
5:
6: <s:actionerror/>
7: <s:form action="partsearchinput">
8: <s:textfield name="partid" label="partid"/>
9: <s:submit value="search"/>
****************************************************************************
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
**********************************************************************
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/decorators # cat basic-theme.jsp
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<body>
<table width="100%" height="100%">
<tr> <td>
<%@ include file="/partsearchinput.jsp"%>
</td></tr>
<tr> <td>
<decorator:body /> <hr />
</td></tr>
<tr> <td> <h2> <p><font color=blue>Copyright XXXXX</font></p> </h2> </td></tr>
</table>
</body>
*******************************************************************************
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce/WEB-INF # cat decorators.xml
<decorators defaultdir="/decorators">
<decorator name="basic-theme" page="basic-theme.jsp">
<pattern>/menu.jsp</pattern>
</decorator>
</decorators>
**********************************************************************************
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat partsearchinput.jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<s:actionerror/>
<s:form action="partsearchinput">
<s:textfield name="partid" label="partid"/>
<s:submit value="search"/>
</s:form>
***********************************************************************************
alpha:/var/apache-tomcat-7.0.34/webapps/ecommerce # cat menu.jsp
<body>
<h1>test</p>
</body>