ITeye博客

struts2 config--browser插件改造

悲剧了 · 2012-04-20 09:15 · 行业应用 · Markdown

**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" %>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。