3

动作代码:

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "userAction")
@AllowedMethods("test")
public class UserAction {

    private static final String[] test = null;
    private static Logger logger = Logger.getLogger(UserAction.class);

    public void test() {
        logger.info("进入action");
    }
}

struts.xml配置文件中:

 <constant name="struts.strictMethodInvocation.methodRegex" value="([a-zA-Z]*)"/>

我想参观

http://localhost:8080/sshe/userAction!Test.action

现在错误:

HTTP 状态 404 - 没有为与上下文路径 [/sshe] 关联的命名空间和操作名称 [/] [userAction test] 映射的操作。

我想知道有没有地方可以设置。我怎样才能访问这个地址?

4

1 回答 1

1

您应该将注释直接放在方法上。因为如果将其放在类上,则默认方法execute()将用于映射。

@ParentPackage("basePackage")
@Namespace("/")
@AllowedMethods("test")
public class UserAction {

    private static final String[] test = null;
    private static Logger logger = Logger.getLogger(UserAction.class);

    @Action(value = "userAction")
    public String test() {
        logger.info("进入action");
        rerurn Action.NONE;
    }
}

action 方法应该返回一个结果,如果你不想执行一个结果,你应该 return Action.NONE


如果您想使用SMI,那么您应该将execute()方法添加到操作类。上面解释了为什么你需要这个方法来映射动作并且返回结果保持不变,因为方法执行仍然是动作方法。您不能使用动作映射来任意执行动作类中的任何方法。

@ParentPackage("basePackage")
@Namespace("/")
@AllowedMethods("test")
@Action(value = "userAction")
public class UserAction {

    private static final String[] test = null;
    private static Logger logger = Logger.getLogger(UserAction.class);

    public String execute() {
        rerurn Action.NONE;
    }


    public String test() {
        logger.info("进入action");
        rerurn Action.NONE;
    }
}

action 方法区分大小写,所以你必须使用 URL

http://localhost:8080/sshe/userAction!test.action
于 2017-06-21T12:53:17.453 回答