Java Struts2不适用于带注释的操作

Java Struts2不适用于带注释的操作,java,jsp,struts2,annotations,struts2-convention-plugin,Java,Jsp,Struts2,Annotations,Struts2 Convention Plugin,我刚开始学习一些Struts2并尝试创建简单的网页。我制作了一个Action类,添加了一些注释,我制作了一些JSP,并在web.xml文件中设置了过滤器,但当我尝试获取页面时,我只看到JSP的工作,没有看到任何Struts2 ClientListAction.java: @Namespace("/") @ResultPath(value = "/") @Result(name = "success", location = "pages/clientList.jsp") public class

我刚开始学习一些Struts2并尝试创建简单的网页。我制作了一个
Action
类,添加了一些注释,我制作了一些JSP,并在
web.xml
文件中设置了过滤器,但当我尝试获取页面时,我只看到JSP的工作,没有看到任何Struts2

ClientListAction.java:

@Namespace("/")
@ResultPath(value = "/")
@Result(name = "success", location = "pages/clientList.jsp")
public class ClientListAction extends ActionSupport {

    private String username = "TEST";

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Test page Struts 2</title>
</head>
<body>
<h4>Hello <s:property value="username"/></h4>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>Clients Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
http://localhost:8080/pages/clientList.jsp
Hello 
clientList.jsp:

@Namespace("/")
@ResultPath(value = "/")
@Result(name = "success", location = "pages/clientList.jsp")
public class ClientListAction extends ActionSupport {

    private String username = "TEST";

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Test page Struts 2</title>
</head>
<body>
<h4>Hello <s:property value="username"/></h4>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>Clients Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
http://localhost:8080/pages/clientList.jsp
Hello 
结果:

@Namespace("/")
@ResultPath(value = "/")
@Result(name = "success", location = "pages/clientList.jsp")
public class ClientListAction extends ActionSupport {

    private String username = "TEST";

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Test page Struts 2</title>
</head>
<body>
<h4>Hello <s:property value="username"/></h4>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>Clients Application</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>
http://localhost:8080/pages/clientList.jsp
Hello 
删除
@ResultPath(value=“/”
并设置
位置
属性的绝对路径。另外,在结果注释中,默认情况下使用
name=“success”
,无需编写。使用将struts2约定插件添加到模块依赖项所需的注释配置。要执行操作,您需要输入url

http://localhost:8080/client-list
如果您的模块已部署到根上下文,或在操作名称之前添加上下文路径。

删除
@ResultPath(value=“/”
),并设置
位置
属性的绝对路径。另外,在结果注释中,默认情况下使用
name=“success”
,无需编写。使用将struts2约定插件添加到模块依赖项所需的注释配置。要执行操作,您需要输入url

http://localhost:8080/client-list

如果您的模块部署到根上下文,或者在操作名称之前添加上下文路径。

URL错误。您正在直接访问jsp。您应该访问该操作。你的url应该是这样的:
localhost:8080\myapp\clientListAction
我试过了,但没有帮助url是错误的。您正在直接访问jsp。您应该访问该操作。你的url应该是这样的:
localhost:8080\myapp\clientListAction
我试过了,但没有帮助