You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "dan.zheng" <cm...@gmail.com> on 2011/09/29 08:34:06 UTC

an odd problem about struts2 annotation

hi,everyone
 I meet an odd problem with struts2 annotation,Let me elaborate it first

import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.beans.factory.annotation.Autowired;

import com.dbappsecurity.portal.model.PortalUser;
import com.dbappsecurity.portal.service.PortalUserService;
import com.opensymphony.xwork2.ActionSupport;

@Results({
    @Result(name="input",location="main.jsp"),
    @Result(name="list",location="list.jsp")
})
public class MainAction extends ActionSupport {
    @Getter @Setter private PortalUser user;
    @Autowired
    private PortalUserService portalUserService;
    public String execute() throws Exception {
        return INPUT;
    }
    @Action("addUser")
    public String addUser() throws Exception {
        portalUserService.addUser(user);
        return listUser();
    }
    @Action("listUser")
    @SkipValidation
    public String listUser() throws Exception {
        List theUserList = portalUserService.getPortalUserList(null);

 ServletActionContext.getRequest().setAttribute("userList",theUserList);
        return "list";
    }
    @Action("modifyUser")
    public String modifyUser() throws Exception {
        List theUserList = portalUserService.getPortalUserList(null);

 ServletActionContext.getRequest().setAttribute("userList",theUserList);
        return "list";
    }

this is the struts2 action class, I configure it correctly and type the url
http://domain/listUser   it will list all users
http://domain/modifyUser it can modify the users
all things go well in tomcat with exploded class files

but when I build with the war file and deploy it into tomcat webapp folder,
the page report
there is no action name listUser
the difference between the two scenario is exploded class files and archived
class files that I compile and jar the action and other class files into it.
I was puzzled about this phenomenon

so any suggestions and advices will be very appreciated!

Re: an odd problem about struts2 annotation

Posted by Jeffrey Black <je...@yahoo.com>.
Is your Tomcat configured for autodeploy=true?

tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html

JB


On Sep 29, 2011, at 10:30 PM, Steven Yang <ke...@gmail.com> wrote:

> for one reason is that struts2 will not scan your classes in jar is that if
> someone tempered with you jar or any of your jar has class with Struts
> Annotations then your user can access these actions without you knowing it.
> I believe this is the same reason why Spring doesnt scan files in jars and
> in order to use them you have to declare them explicitly in xml files.
> 
> On Fri, Sep 30, 2011 at 10:49 AM, dan.zheng <cm...@gmail.com> wrote:
> 
>> I know some tricky about this problem
>> the struts convention will scan action class in the specific package
>> for example:
>> struts.convention.package.locators indicate the action class suffix
>> 
>> but when you jar the classes,I suppose that struts2 can't scan the action
>> class
>> in jar files,if this is true,I will always deploy war with class files
>> exploded,I want to find
>> a workaround,thanks
>> 
>> On Fri, Sep 30, 2011 at 10:22 AM, dan.zheng <cm...@gmail.com> wrote:
>> 
>>> I jar the classes and put it into WEB-INF/lib
>>> of course you know,the war will package all jars and jsp files in bundle
>>> why the struts2 can't scan classes in WEB-INF/lib?
>>> 
>>> 
>>> On Fri, Sep 30, 2011 at 10:05 AM, Steven Yang <kenshin520@gmail.com
>>> wrote:
>>> 
>>>> sorry just to be clear
>>>> did you "jar" the classes or did you "war" the classes?
>>>> 
>>>> if you "jar" the classes then i dont think struts 2 will scan your
>> classes
>>>> in jars.
>>>> 
>>>> On Thu, Sep 29, 2011 at 2:34 PM, dan.zheng <cm...@gmail.com> wrote:
>>>> 
>>>>> hi,everyone
>>>>> I meet an odd problem with struts2 annotation,Let me elaborate it
>> first
>>>>> 
>>>>> import java.util.List;
>>>>> 
>>>>> import lombok.Getter;
>>>>> import lombok.Setter;
>>>>> 
>>>>> import org.apache.commons.lang.StringUtils;
>>>>> import org.apache.struts2.ServletActionContext;
>>>>> import org.apache.struts2.convention.annotation.Action;
>>>>> import org.apache.struts2.convention.annotation.Result;
>>>>> import org.apache.struts2.convention.annotation.Results;
>>>>> import org.apache.struts2.interceptor.validation.SkipValidation;
>>>>> import org.springframework.beans.factory.annotation.Autowired;
>>>>> 
>>>>> import com.dbappsecurity.portal.model.PortalUser;
>>>>> import com.dbappsecurity.portal.service.PortalUserService;
>>>>> import com.opensymphony.xwork2.ActionSupport;
>>>>> 
>>>>> @Results({
>>>>>   @Result(name="input",location="main.jsp"),
>>>>>   @Result(name="list",location="list.jsp")
>>>>> })
>>>>> public class MainAction extends ActionSupport {
>>>>>   @Getter @Setter private PortalUser user;
>>>>>   @Autowired
>>>>>   private PortalUserService portalUserService;
>>>>>   public String execute() throws Exception {
>>>>>       return INPUT;
>>>>>   }
>>>>>   @Action("addUser")
>>>>>   public String addUser() throws Exception {
>>>>>       portalUserService.addUser(user);
>>>>>       return listUser();
>>>>>   }
>>>>>   @Action("listUser")
>>>>>   @SkipValidation
>>>>>   public String listUser() throws Exception {
>>>>>       List theUserList = portalUserService.getPortalUserList(null);
>>>>> 
>>>>> 
>> ServletActionContext.getRequest().setAttribute("userList",theUserList);
>>>>>       return "list";
>>>>>   }
>>>>>   @Action("modifyUser")
>>>>>   public String modifyUser() throws Exception {
>>>>>       List theUserList = portalUserService.getPortalUserList(null);
>>>>> 
>>>>> 
>> ServletActionContext.getRequest().setAttribute("userList",theUserList);
>>>>>       return "list";
>>>>>   }
>>>>> 
>>>>> this is the struts2 action class, I configure it correctly and type
>> the
>>>> url
>>>>> http://domain/listUser   it will list all users
>>>>> http://domain/modifyUser it can modify the users
>>>>> all things go well in tomcat with exploded class files
>>>>> 
>>>>> but when I build with the war file and deploy it into tomcat webapp
>>>> folder,
>>>>> the page report
>>>>> there is no action name listUser
>>>>> the difference between the two scenario is exploded class files and
>>>>> archived
>>>>> class files that I compile and jar the action and other class files
>> into
>>>>> it.
>>>>> I was puzzled about this phenomenon
>>>>> 
>>>>> so any suggestions and advices will be very appreciated!
>>>>> 
>>>> 
>>> 
>>> 
>> 

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


Re: an odd problem about struts2 annotation

Posted by Steven Yang <ke...@gmail.com>.
for one reason is that struts2 will not scan your classes in jar is that if
someone tempered with you jar or any of your jar has class with Struts
Annotations then your user can access these actions without you knowing it.
I believe this is the same reason why Spring doesnt scan files in jars and
in order to use them you have to declare them explicitly in xml files.

On Fri, Sep 30, 2011 at 10:49 AM, dan.zheng <cm...@gmail.com> wrote:

> I know some tricky about this problem
> the struts convention will scan action class in the specific package
> for example:
> struts.convention.package.locators indicate the action class suffix
>
> but when you jar the classes,I suppose that struts2 can't scan the action
> class
> in jar files,if this is true,I will always deploy war with class files
> exploded,I want to find
> a workaround,thanks
>
> On Fri, Sep 30, 2011 at 10:22 AM, dan.zheng <cm...@gmail.com> wrote:
>
> > I jar the classes and put it into WEB-INF/lib
> > of course you know,the war will package all jars and jsp files in bundle
> > why the struts2 can't scan classes in WEB-INF/lib?
> >
> >
> > On Fri, Sep 30, 2011 at 10:05 AM, Steven Yang <kenshin520@gmail.com
> >wrote:
> >
> >> sorry just to be clear
> >> did you "jar" the classes or did you "war" the classes?
> >>
> >> if you "jar" the classes then i dont think struts 2 will scan your
> classes
> >> in jars.
> >>
> >> On Thu, Sep 29, 2011 at 2:34 PM, dan.zheng <cm...@gmail.com> wrote:
> >>
> >> > hi,everyone
> >> >  I meet an odd problem with struts2 annotation,Let me elaborate it
> first
> >> >
> >> > import java.util.List;
> >> >
> >> > import lombok.Getter;
> >> > import lombok.Setter;
> >> >
> >> > import org.apache.commons.lang.StringUtils;
> >> > import org.apache.struts2.ServletActionContext;
> >> > import org.apache.struts2.convention.annotation.Action;
> >> > import org.apache.struts2.convention.annotation.Result;
> >> > import org.apache.struts2.convention.annotation.Results;
> >> > import org.apache.struts2.interceptor.validation.SkipValidation;
> >> > import org.springframework.beans.factory.annotation.Autowired;
> >> >
> >> > import com.dbappsecurity.portal.model.PortalUser;
> >> > import com.dbappsecurity.portal.service.PortalUserService;
> >> > import com.opensymphony.xwork2.ActionSupport;
> >> >
> >> > @Results({
> >> >    @Result(name="input",location="main.jsp"),
> >> >    @Result(name="list",location="list.jsp")
> >> > })
> >> > public class MainAction extends ActionSupport {
> >> >    @Getter @Setter private PortalUser user;
> >> >    @Autowired
> >> >    private PortalUserService portalUserService;
> >> >    public String execute() throws Exception {
> >> >        return INPUT;
> >> >    }
> >> >    @Action("addUser")
> >> >    public String addUser() throws Exception {
> >> >        portalUserService.addUser(user);
> >> >        return listUser();
> >> >    }
> >> >    @Action("listUser")
> >> >    @SkipValidation
> >> >    public String listUser() throws Exception {
> >> >        List theUserList = portalUserService.getPortalUserList(null);
> >> >
> >> >
>  ServletActionContext.getRequest().setAttribute("userList",theUserList);
> >> >        return "list";
> >> >    }
> >> >    @Action("modifyUser")
> >> >    public String modifyUser() throws Exception {
> >> >        List theUserList = portalUserService.getPortalUserList(null);
> >> >
> >> >
>  ServletActionContext.getRequest().setAttribute("userList",theUserList);
> >> >        return "list";
> >> >    }
> >> >
> >> > this is the struts2 action class, I configure it correctly and type
> the
> >> url
> >> > http://domain/listUser   it will list all users
> >> > http://domain/modifyUser it can modify the users
> >> > all things go well in tomcat with exploded class files
> >> >
> >> > but when I build with the war file and deploy it into tomcat webapp
> >> folder,
> >> > the page report
> >> > there is no action name listUser
> >> > the difference between the two scenario is exploded class files and
> >> > archived
> >> > class files that I compile and jar the action and other class files
> into
> >> > it.
> >> > I was puzzled about this phenomenon
> >> >
> >> > so any suggestions and advices will be very appreciated!
> >> >
> >>
> >
> >
>

Re: an odd problem about struts2 annotation

Posted by "dan.zheng" <cm...@gmail.com>.
I know some tricky about this problem
the struts convention will scan action class in the specific package
for example:
struts.convention.package.locators indicate the action class suffix

but when you jar the classes,I suppose that struts2 can't scan the action
class
in jar files,if this is true,I will always deploy war with class files
exploded,I want to find
a workaround,thanks

On Fri, Sep 30, 2011 at 10:22 AM, dan.zheng <cm...@gmail.com> wrote:

> I jar the classes and put it into WEB-INF/lib
> of course you know,the war will package all jars and jsp files in bundle
> why the struts2 can't scan classes in WEB-INF/lib?
>
>
> On Fri, Sep 30, 2011 at 10:05 AM, Steven Yang <ke...@gmail.com>wrote:
>
>> sorry just to be clear
>> did you "jar" the classes or did you "war" the classes?
>>
>> if you "jar" the classes then i dont think struts 2 will scan your classes
>> in jars.
>>
>> On Thu, Sep 29, 2011 at 2:34 PM, dan.zheng <cm...@gmail.com> wrote:
>>
>> > hi,everyone
>> >  I meet an odd problem with struts2 annotation,Let me elaborate it first
>> >
>> > import java.util.List;
>> >
>> > import lombok.Getter;
>> > import lombok.Setter;
>> >
>> > import org.apache.commons.lang.StringUtils;
>> > import org.apache.struts2.ServletActionContext;
>> > import org.apache.struts2.convention.annotation.Action;
>> > import org.apache.struts2.convention.annotation.Result;
>> > import org.apache.struts2.convention.annotation.Results;
>> > import org.apache.struts2.interceptor.validation.SkipValidation;
>> > import org.springframework.beans.factory.annotation.Autowired;
>> >
>> > import com.dbappsecurity.portal.model.PortalUser;
>> > import com.dbappsecurity.portal.service.PortalUserService;
>> > import com.opensymphony.xwork2.ActionSupport;
>> >
>> > @Results({
>> >    @Result(name="input",location="main.jsp"),
>> >    @Result(name="list",location="list.jsp")
>> > })
>> > public class MainAction extends ActionSupport {
>> >    @Getter @Setter private PortalUser user;
>> >    @Autowired
>> >    private PortalUserService portalUserService;
>> >    public String execute() throws Exception {
>> >        return INPUT;
>> >    }
>> >    @Action("addUser")
>> >    public String addUser() throws Exception {
>> >        portalUserService.addUser(user);
>> >        return listUser();
>> >    }
>> >    @Action("listUser")
>> >    @SkipValidation
>> >    public String listUser() throws Exception {
>> >        List theUserList = portalUserService.getPortalUserList(null);
>> >
>> >  ServletActionContext.getRequest().setAttribute("userList",theUserList);
>> >        return "list";
>> >    }
>> >    @Action("modifyUser")
>> >    public String modifyUser() throws Exception {
>> >        List theUserList = portalUserService.getPortalUserList(null);
>> >
>> >  ServletActionContext.getRequest().setAttribute("userList",theUserList);
>> >        return "list";
>> >    }
>> >
>> > this is the struts2 action class, I configure it correctly and type the
>> url
>> > http://domain/listUser   it will list all users
>> > http://domain/modifyUser it can modify the users
>> > all things go well in tomcat with exploded class files
>> >
>> > but when I build with the war file and deploy it into tomcat webapp
>> folder,
>> > the page report
>> > there is no action name listUser
>> > the difference between the two scenario is exploded class files and
>> > archived
>> > class files that I compile and jar the action and other class files into
>> > it.
>> > I was puzzled about this phenomenon
>> >
>> > so any suggestions and advices will be very appreciated!
>> >
>>
>
>

Re: an odd problem about struts2 annotation

Posted by "dan.zheng" <cm...@gmail.com>.
I jar the classes and put it into WEB-INF/lib
of course you know,the war will package all jars and jsp files in bundle
why the struts2 can't scan classes in WEB-INF/lib?

On Fri, Sep 30, 2011 at 10:05 AM, Steven Yang <ke...@gmail.com> wrote:

> sorry just to be clear
> did you "jar" the classes or did you "war" the classes?
>
> if you "jar" the classes then i dont think struts 2 will scan your classes
> in jars.
>
> On Thu, Sep 29, 2011 at 2:34 PM, dan.zheng <cm...@gmail.com> wrote:
>
> > hi,everyone
> >  I meet an odd problem with struts2 annotation,Let me elaborate it first
> >
> > import java.util.List;
> >
> > import lombok.Getter;
> > import lombok.Setter;
> >
> > import org.apache.commons.lang.StringUtils;
> > import org.apache.struts2.ServletActionContext;
> > import org.apache.struts2.convention.annotation.Action;
> > import org.apache.struts2.convention.annotation.Result;
> > import org.apache.struts2.convention.annotation.Results;
> > import org.apache.struts2.interceptor.validation.SkipValidation;
> > import org.springframework.beans.factory.annotation.Autowired;
> >
> > import com.dbappsecurity.portal.model.PortalUser;
> > import com.dbappsecurity.portal.service.PortalUserService;
> > import com.opensymphony.xwork2.ActionSupport;
> >
> > @Results({
> >    @Result(name="input",location="main.jsp"),
> >    @Result(name="list",location="list.jsp")
> > })
> > public class MainAction extends ActionSupport {
> >    @Getter @Setter private PortalUser user;
> >    @Autowired
> >    private PortalUserService portalUserService;
> >    public String execute() throws Exception {
> >        return INPUT;
> >    }
> >    @Action("addUser")
> >    public String addUser() throws Exception {
> >        portalUserService.addUser(user);
> >        return listUser();
> >    }
> >    @Action("listUser")
> >    @SkipValidation
> >    public String listUser() throws Exception {
> >        List theUserList = portalUserService.getPortalUserList(null);
> >
> >  ServletActionContext.getRequest().setAttribute("userList",theUserList);
> >        return "list";
> >    }
> >    @Action("modifyUser")
> >    public String modifyUser() throws Exception {
> >        List theUserList = portalUserService.getPortalUserList(null);
> >
> >  ServletActionContext.getRequest().setAttribute("userList",theUserList);
> >        return "list";
> >    }
> >
> > this is the struts2 action class, I configure it correctly and type the
> url
> > http://domain/listUser   it will list all users
> > http://domain/modifyUser it can modify the users
> > all things go well in tomcat with exploded class files
> >
> > but when I build with the war file and deploy it into tomcat webapp
> folder,
> > the page report
> > there is no action name listUser
> > the difference between the two scenario is exploded class files and
> > archived
> > class files that I compile and jar the action and other class files into
> > it.
> > I was puzzled about this phenomenon
> >
> > so any suggestions and advices will be very appreciated!
> >
>

Re: an odd problem about struts2 annotation

Posted by Steven Yang <ke...@gmail.com>.
sorry just to be clear
did you "jar" the classes or did you "war" the classes?

if you "jar" the classes then i dont think struts 2 will scan your classes
in jars.

On Thu, Sep 29, 2011 at 2:34 PM, dan.zheng <cm...@gmail.com> wrote:

> hi,everyone
>  I meet an odd problem with struts2 annotation,Let me elaborate it first
>
> import java.util.List;
>
> import lombok.Getter;
> import lombok.Setter;
>
> import org.apache.commons.lang.StringUtils;
> import org.apache.struts2.ServletActionContext;
> import org.apache.struts2.convention.annotation.Action;
> import org.apache.struts2.convention.annotation.Result;
> import org.apache.struts2.convention.annotation.Results;
> import org.apache.struts2.interceptor.validation.SkipValidation;
> import org.springframework.beans.factory.annotation.Autowired;
>
> import com.dbappsecurity.portal.model.PortalUser;
> import com.dbappsecurity.portal.service.PortalUserService;
> import com.opensymphony.xwork2.ActionSupport;
>
> @Results({
>    @Result(name="input",location="main.jsp"),
>    @Result(name="list",location="list.jsp")
> })
> public class MainAction extends ActionSupport {
>    @Getter @Setter private PortalUser user;
>    @Autowired
>    private PortalUserService portalUserService;
>    public String execute() throws Exception {
>        return INPUT;
>    }
>    @Action("addUser")
>    public String addUser() throws Exception {
>        portalUserService.addUser(user);
>        return listUser();
>    }
>    @Action("listUser")
>    @SkipValidation
>    public String listUser() throws Exception {
>        List theUserList = portalUserService.getPortalUserList(null);
>
>  ServletActionContext.getRequest().setAttribute("userList",theUserList);
>        return "list";
>    }
>    @Action("modifyUser")
>    public String modifyUser() throws Exception {
>        List theUserList = portalUserService.getPortalUserList(null);
>
>  ServletActionContext.getRequest().setAttribute("userList",theUserList);
>        return "list";
>    }
>
> this is the struts2 action class, I configure it correctly and type the url
> http://domain/listUser   it will list all users
> http://domain/modifyUser it can modify the users
> all things go well in tomcat with exploded class files
>
> but when I build with the war file and deploy it into tomcat webapp folder,
> the page report
> there is no action name listUser
> the difference between the two scenario is exploded class files and
> archived
> class files that I compile and jar the action and other class files into
> it.
> I was puzzled about this phenomenon
>
> so any suggestions and advices will be very appreciated!
>