开发者

Struts2 annotations (Convention Plugin)

I meet an odd problem with struts2 annotation, let me elaborate it first

@Results({
    @Result(name = "input", location = "main.jsp"),
    @Result(name = "list", location = "list.jsp")
})
public class MainAction extends ActionSupport {

    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")
    pub开发者_运维技巧lic String modifyUser() throws Exception {
        List theUserList = portalUserService.getPortalUserList(null);
        ServletActionContext.getRequest().setAttribute("userList", theUserList);
        return "list";
    }

    public void validate() {
        if (user != null && StringUtils.isBlank(user.getUserName()))
            addFieldError("accountBean.userName", "User name is required.");
        System.out.println("validate @@@@@");
    }

    public PortalUser getUser() {
        return user;
    }

    public void setUser(PortalUser user) {
        this.user = user;
    }
}

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!


I experiment as followings and conclude it that with struts2 annotation,the action class can't move into jar files,it must be located in your WEB-INF/classes

I acknowledge that the struts2 convention will scan action class in the specific package,so I left only the action classes in WEB-INF/classes/.../action folder ,jar other class files and put it into WEB-INF/lib, it's done


By default the plugin does not scan jars or the classpath, solely WEB-INF/classes. You might want to see the plugin's Configuration Reference and look for the value struts.convention.action.includeJars, which lets you list the jars where you also want to look for the files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜