如果参数名称和值不定,参数个数也不定的话,你的href中不光要有值,参数名也应该包含在里面:
搜索
然后基于上面的href,你可以自己写一个Filter,然后在Filter的doFilter方法里面对url进行重写,然后forward到你重写后的url。算法很简单:
[code="java"]public void doFilter(ServletRequest request,ServletResponse response,
FilterChain chain) throws IOException, ServletException{
String reqURI = request.getRequestURI();
if(reqURI.startsWith("/xxx/search/")){
String reqQueryStr = request.getQueryString();
StringTokenizer st = new StringTokenizer(reqQueryStr ,"/");
StringBuffer strbuf = new StringBuffer();
strbuf.append("/search.xz?");
String paramName = null;
String paramValue = null;
while (st.hasMoreTokens()) {
paramName = st.nextToken();
paramValue = st.nextToken();
strbuf.append(paramName + "=" + paramValue + "&");
}
if(strbuf.endsWith("?") || strbuf.endsWith("&"){
strbuf.deleteCharAt(strbuf.length()-1);
}
request.getRequestDispatcher(strbuf).forward(request,response);
}else{
chain.doFilter();
}
}[/code]
然后把自定义的Filter配置到web.xml文件中即可。
上面的代码没有编译,你自己再调试一下看看,应该问题不大,呵呵。