config--browser插件提供了很不错的功能,当我们用注解的时候,这个功能就显得很重要,查找路径和对应的类与方法能解决非xml的好处
但当我们项目越来越大,一个namespace下面有好多actionName,这些actionName甚至还相近,本身的查找方式已经无法满足,看看源码,改造一把
想要的结果:每次直接输入全部路径,然后提交
1.给出对应的action全名称--包名+类名
2.给出对应调用的方法
ps:项目中用到了urlRewriter就不行了
public class ShowAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String url;
protected ConfigurationHelper configHelper;
private ActionConfig actionConfig;
@Inject
public void setConfigurationHelper(ConfigurationHelper cfg) {
this.configHelper = cfg;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String execute() throws Exception {
if(!StringUtils.isEmpty(url)){
processUrl();
}
return "show";
}
public ActionConfig getActionConfig() {
return actionConfig;
}
private void processUrl(){
//获取项目的根路径
HttpServletRequest request=ServletActionContext.getRequest();
String baseUrl=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
//过滤掉传值路径
int start=baseUrl.length();
String path=url.substring(start);
//取出namespaces actionName
int end=path.lastIndexOf(".");
String endStr=path.substring(0,end);
String actionName=endStr.substring(endStr.lastIndexOf("/")+1,endStr.length());
String namespace=endStr.substring(0,endStr.lastIndexOf("/"));
actionConfig=configHelper.getActionConfig(namespace, actionName);
}
}
对应jsp页面只需要去除ationConfig
引用
<%@ page contentType="text/html; charset=utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
${actionMessages[0]}
${actionErrors[1]}
<form action="../show/show.action">
<input type="text" name="url"/>
<input type="submit" value="查询">
</form>
${url}查询结果如下:
className-- ${actionConfig.className}<br/>
methodName-- ${actionConfig.methodName}<br/>
</body>
</html>
分享到:
相关推荐
默认的struts2-config-browser-plugin包中的ftl文件include标签路径用的相对路径,会找到包内的include文件,将包内ftl里include的路径改成的/开头的全路径。
struts2-config-browser-plugin-2.1.8.1.jar
struts2-config-browser-plugin-2.2.3.jar
cascade.zip,用于Scala应用程序的级联JSON公共库和模式
struts2.1.6-config-browser-plugin.api.chm struts2.1.6-config-browser-plugin.api.chm
struts2-config-browser-plugin-2.1.6.jar
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
struts-config.xml struts标准配置文件 struts-config
2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9791(S2-048),主要受影响的Struts版本为:2.3.x。 攻击者可以构造恶意的字段值...
Struts框架中struts-config.xml文件配置小结
struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, struts2-dojo-plugin-2.3.30.jar, struts2-dwr-plugin-2.3.30.jar, struts2-embeddedjsp-plugin-...
2.5.10.1.jar,struts2-config-browser-plugin-2.5.10.1.jar,struts2-convention-plugin-2.5.10.1.jar,struts2-dwr-plugin-2.5.10.1.jar,struts2-embeddedjsp-plugin-2.5.10.1.jar,struts2-gxp-plugin-2.5.10.1....
-- 为修复struts2 s2-016、s2-017漏洞,重写DefaultActionMapper --> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myDefaultActionMapper" class=...
struts2-config-browser-plugin-2.5.2.jar, struts2-convention-plugin-2.5.2.jar, struts2-core-2.5.2.jar, struts2-dwr-plugin-2.5.2.jar, struts2-embeddedjsp-plugin-2.5.2.jar, struts2-gxp-plugin-2.5.2.jar, ...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar
最新的struts2-jquery-plugin插件3.3.3,包括jquery-ui和grid,使用标签实现。
struts2-json-plugin,Struts JSON插件
struts2学习-29集带插件