You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Natta Wang <xe...@gmail.com> on 2020/08/27 09:16:05 UTC

Struts 1 -> Struts 2 migration session parameters not found

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?

Any help or suggestion are appreciated.
Thanks.

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


Re: Struts 1 -> Struts 2 migration session parameters not found

Posted by M Huzaifah <mh...@gmail.com>.
Hii Natta Wang,

Are you try using session interceptor? In java, the session could access
using ServletActionContext.getRequest().getSession(); it will return
servlet HttpSession and use getAttribute() method to ge your particular
session by given sessionAttribut name.

To access session in jsp, i usualy using
${sessionScope.yourSesionAttributName}

Regards...

On Thu, Aug 27, 2020, 6:17 PM Natta Wang <xe...@gmail.com> wrote:

> 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?
>
> Any help or suggestion are appreciated.
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts 1 -> Struts 2 migration session parameters not found

Posted by Natta Wang <xe...@gmail.com>.
Thanks to you guys.
Now I succeed implement session parameters that I expected to appear in Struts2 action by implement with SessionAware.

On 2020/08/27 18:31:20, Lukasz Lenart <lu...@apache.org> wrote: 
> czw., 27 sie 2020 o 13:17 Natta Wang <xe...@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-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


Re: Struts 1 -> Struts 2 migration session parameters not found

Posted by Lukasz Lenart <lu...@apache.org>.
czw., 27 sie 2020 o 13:17 Natta Wang <xe...@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org