---
title: "struts2 config--browser插件改造"
author: "悲剧了"
date: "2012-04-20T09:15:49Z"
tags: []
categories: ["行业应用"]
slug: "struts2-config-browser"
draft: false
lastmod: "2012-04-20T09:16:21Z"
id: 1490963
url: "https://blognojava.iteye.com/blog/1490963"
---

**config--browser插件提供了很不错的功能,当我们用注解的时候,这个功能就显得很重要,查找路径和对应的类与方法能解决非xml的好处

    但当我们项目越来越大,一个namespace下面有好多actionName,这些actionName甚至还相近,本身的查找方式已经无法满足,看看源码,改造一把
想要的结果:每次直接输入全部路径,然后提交
1.给出对应的action全名称--包名+类名  
2.给出对应调用的方法
ps:项目中用到了urlRewriter就不行了**

```java

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>
>