Struts2注释(约定插件)

发布于 2024-12-07 13:19:52 字数 1811 浏览 0 评论 0原文

我遇到了一个关于 struts2 注释的奇怪问题,让我先详细说明一下,

@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")
    public 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;
    }
}

这是 struts2 操作类,我正确配置它并输入 url

  • http://domain/listUser 它将列出所有用户
  • http://domain/modifyUser 它可以修改用户,

在带有分解的类文件的tomcat中一切顺利

但是当我使用war文件构建并将其部署到tomcat webapp文件夹中时,页面报告 没有操作名称 listUser。

这两个场景之间的区别是分解的类文件和存档的类文件,我将操作和其他类文件编译并打包到其中。

我对这个现象感到很困惑。

因此,任何建议和建议将不胜感激!

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")
    public 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

死开点丶别碍眼 2024-12-14 13:19:52

我进行了如下实验并得出结论,使用struts2注释,动作类不能移动到jar文件中,它必须位于您的WEB-INF/classes中

我承认struts2约定将扫描特定包中的动作类,所以我只留下WEB-INF/classes/.../action文件夹中的action类,jar其他类文件并将其放入WEB-INF/lib中,就完成了

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

独﹏钓一江月 2024-12-14 13:19:52

默认情况下,该插件不扫描 jar 或类路径,仅扫描 WEB-INF/classes。您可能想查看插件的配置参考并查找值 struts.convention.action.includeJars,它可以让您列出您还想在其中查找文件的 jar。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文