首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Struts 2操作url映射

Struts 2操作url映射
EN

Stack Overflow用户
提问于 2020-10-12 19:13:18
回答 1查看 51关注 0票数 0

我已经启用了Struts2约定插件。

代码语言:javascript
复制
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访问?

EN

回答 1

Stack Overflow用户

发布于 2020-10-16 23:31:45

当调用http://localhost:8080/customer时,Struts2将找到映射到相应名称空间的操作(即IndexAction),并重定向到execute() (默认)方法。

如果您不想要此行为,可以删除execute()并在类中创建特定方法

代码语言:javascript
复制
public String index() {
  return SUCCESS;
}

对应的URL是http://localhost:8080/customer!index (http://localhost:8080/customer!index.action也可以)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64316744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档