0
回答
urlrewriterGET请求参数配置之后获取不到
终于搞明白,存储TCO原来是这样算的>>>   

在urlrewriter.xml配置文件中

<rule>
        <from>/(\w+)/(\w+).html(\?.*)?$</from>
        <to>/$1?q=$2&amp;$3</to>
</rule>



$1和$2都没有问题,但是$3拿不到。

BaseServlet

@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String q = request.getParameter("q");
		if (StringUtil.isEmpty(q)) {
			q = "index";
		}
		Class c = this.getClass();
		Method method = null;
		String result = "";
		try {
			method = c.getMethod(q, HttpServletRequest.class,HttpServletResponse.class);
			result = (String) method.invoke(this, request,response);
		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
			e.printStackTrace();
		}
		if (StringUtil.notEmpty(result)) {
			if (JsonUtil.isJson(result)) {
				response.getWriter().print(result);
				return ;
			}
			request.getRequestDispatcher(prefix + result + suffix).forward(request, response);
		} else {
			request.getRequestDispatcher("index" + suffix).forward(request, response);
		}
	}



IndexServlet

public String info(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//    	request.getRequestDispatcher("WEB-INF/pages/index.jsp").forward(request,response);
    	String params = request.getQueryString();
    	request.setAttribute("params", params);
    	return "t2/index";
    }



String params = request.getQueryString();

请求地址:http://127.0.0.1/TinyServlet/index/info.html?m=hh

理想条件下,还原后的真实请求路径应该是:http://127.0.0.1/TinyServlet/index?q=info&m=hh

DEBUG的时候确request里面实能看到有两参数,{q=[Ljava.lang.String;@6c8b789, m=[Ljava.lang.String;@5d76a8de},但是params值为 q=info&,也就是后面html?xxxxx的参数没有拼上去,而是到了requestBody里面,变成了post数据。

请问一下rule该如何修改



举报
Kylin_Shaw
发帖于11个月前 0回/203阅
顶部