You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lukasz Lenart <lu...@googlemail.com> on 2009/02/25 11:38:39 UTC

Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

2009/2/25 Gordian Yuan <go...@gmail.com>:
> I want to know what is there a way through the ognl tag in struts2 access to
> the HttpServletRequest getRemoteUser() method
> I google a lot of about this issue but i can't find any resolvent.
> Someone know how to do it?
> Any input will be great ... Thank you

#request.remoteUser ?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

Posted by Gordian Yuan <go...@gmail.com>.
Hi Wes,

Thank you for your wonderful answer.These two methods are very good solution
to my problem.

THANK YOU!!!

Gordian

On Thu, Feb 26, 2009 at 10:34 AM, Wes Wannemacher <we...@wantii.com> wrote:

> On Wednesday 25 February 2009 21:15:09 Gordian Yuan wrote:
> > Hi, Lukasz
> >
> > All I know is # request is a Map, it is only stored request of
> attributes,
> > it does not have getRemoteUser().
> >
> > Now I have to use EL and ordinary html tags replace struts2 tags to solve
> > this problem.
> >
> > However, thank you for your reply ...
> >
>
> If you have static methods turned on for OGNL, you might be able to use the
> following expression -
>
> @com.opensymphony.xwork2.ActionContext@getContext
> ().get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getRemoteUser()
>
> It's ugly, but it should work. Another thing to try is to whip up a quick
> interceptor that pushes the String you want onto the value stack...
> Something
> like the following should work -
>
> ActionContext context = ActionContext.getContext();
> context.getValueStack().set(
>                "remoteUser",
>
>  ((HttpServletRequest)(context.get(HTTP_REQUEST))).getRemoteUser());
>
> Then, any action that is intercepted by this interceptor could have a tag -
> <s:property value="#remoteUser"/>
>
> Of course, EL is fine too...
>
> Struts doesn't expose many Servlet Spec objects as a design choice. There
> are
> obviously times when it's necessary. Given adequate time, you might be able
> to
> move away from the Serlvet Spec by incorporating something like Spring
> Security, etc. But, that may not be practical, so stick with EL if you want
> the quick solution, or write an interceptor if you want to make the
> solution
> more Struts-y, and if you have enough time and want to gain a whole heck of
> a
> lot of functionality, then try out Spring Security.
>
> -Wes
>
> -Wes
> --
>
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

Posted by Wes Wannemacher <we...@wantii.com>.
On Wednesday 25 February 2009 21:15:09 Gordian Yuan wrote:
> Hi, Lukasz
>
> All I know is # request is a Map, it is only stored request of attributes,
> it does not have getRemoteUser().
>
> Now I have to use EL and ordinary html tags replace struts2 tags to solve
> this problem.
>
> However, thank you for your reply ...
>

If you have static methods turned on for OGNL, you might be able to use the 
following expression -

@com.opensymphony.xwork2.ActionContext@getContext().get(@org.apache.struts2.StrutsStatics@HTTP_REQUEST).getRemoteUser()

It's ugly, but it should work. Another thing to try is to whip up a quick 
interceptor that pushes the String you want onto the value stack... Something 
like the following should work - 

ActionContext context = ActionContext.getContext();
context.getValueStack().set(
		"remoteUser", 
		((HttpServletRequest)(context.get(HTTP_REQUEST))).getRemoteUser());

Then, any action that is intercepted by this interceptor could have a tag -
<s:property value="#remoteUser"/>

Of course, EL is fine too... 

Struts doesn't expose many Servlet Spec objects as a design choice. There are 
obviously times when it's necessary. Given adequate time, you might be able to 
move away from the Serlvet Spec by incorporating something like Spring 
Security, etc. But, that may not be practical, so stick with EL if you want 
the quick solution, or write an interceptor if you want to make the solution 
more Struts-y, and if you have enough time and want to gain a whole heck of a 
lot of functionality, then try out Spring Security.

-Wes

-Wes
-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


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


Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

Posted by Gordian Yuan <go...@gmail.com>.
Hi, Lukasz

All I know is # request is a Map, it is only stored request of attributes,
it does not have getRemoteUser().

Now I have to use EL and ordinary html tags replace struts2 tags to solve
this problem.

However, thank you for your reply ...

Gordian


On Wed, Feb 25, 2009 at 11:54 PM, Lukasz Lenart <
lukasz.lenart@googlemail.com> wrote:

> 2009/2/25 Gordian Yuan <go...@gmail.com>:
> > #request.remoteUser actual is request.getAttribute("remoteUser"), not i
> want
> > request.getRemoteUser()
>
> Yes, you're right try #request.getRemoteUser()
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/2/25 Gordian Yuan <go...@gmail.com>:
> #request.remoteUser actual is request.getAttribute("remoteUser"), not i want
> request.getRemoteUser()

Yes, you're right try #request.getRemoteUser()


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: How to user HttpServletRequest getRemoteUser() method on struts2 tag?

Posted by Gordian Yuan <go...@gmail.com>.
Hi, Lukasz

Thank for your reply

#request.remoteUser actual is request.getAttribute("remoteUser"), not i want
request.getRemoteUser()

Gordian

On Wed, Feb 25, 2009 at 6:38 PM, Lukasz Lenart <lukasz.lenart@googlemail.com
> wrote:

> 2009/2/25 Gordian Yuan <go...@gmail.com>:
> > I want to know what is there a way through the ognl tag in struts2 access
> to
> > the HttpServletRequest getRemoteUser() method
> > I google a lot of about this issue but i can't find any resolvent.
> > Someone know how to do it?
> > Any input will be great ... Thank you
>
> #request.remoteUser ?
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>