czw., 27 sie 2020 o 13:17 Natta Wang <xeno...@gmail.com> napisał(a):
>
> I start to migrate from Struts 1 to Struts 2 and found a problem that I want 
> to ask for help with the session.
>
> In Struts 1 web.xml, I have a Filter class that maps to servlet and when it 
> be called, it will set a parameter with an object.
>
> All Struts 1 JSP pages can access the session that has those parameters, and 
> what I did to the new Action class of Struts 2 is implements with 
> SessionAware,
> in the class if found session object by 
> ServletActionContext.getRequest().getSession(), but cannot found the 
> parameter with the parameter name that I expected it has.
>
> What I tried is added new filter-mapping in the web.xml file, which map 
> url-pattern to Struts 2 Action class (same with that mapped to servlet I 
> mentioned above), hope it will be called when opening with a specific URL but 
> I failed as it comes out like the not set version.
>
> Can someone guide me on how to make the session and all parameters visible in 
> the Action class and JSP page?
>
> And one more thing, I use <s:include> the header page and header page also 
> refers to those session parameters. Do I need to implement any configuration 
> to make header JSP can access the session?

By using SessionAware, the session is going to be injected in your
action [1], in tags or JSPs you can use a named scope #session [2] to
access the attributes. But please be aware that Struts2 won't create
the session if it doesn't exist. You must use Session Create
Interceptor [3] to forcly create the session.

[1] https://struts.apache.org/core-developers/servlet-config-interceptor.html
[2] https://struts.apache.org/tag-developers/ognl-basics#struts-2-named-objects
[3] https://struts.apache.org/core-developers/create-session-interceptor.html


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to