如何解决Struts 2操作URL映射
我已启用Struts 2约定插件。
package system;
@Namespace("/customer")
public class IndexAction extends ActionSupport {
public execute() {
return SUCCESS;
}
}
如果我输入http://localhost:8080/customer/
和http://localhost:8080/customer/index.action
,则两者都可以到达同一页面。
如何禁用http://localhost:8080/customer/
并仅允许使用http://localhost:8080/customer/index.action
进行访问?
解决方法
调用http://localhost:8080/customer
时,Struts2将找到与相应名称空间映射的Action(即IndexAction)并重定向到execute()
(默认)方法。
如果您不希望出现这种情况,可以删除execute()
并在类中创建特定的方法
public String index() {
return SUCCESS;
}
相应的URL为http://localhost:8080/customer!index
(http://localhost:8080/customer!index.action
也适用)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。