下面代码中有Globals.ORIGINAL_URI_KEY,INCLUDE_PATH_INFO,INCLUDE_SERVLET_PATH等东东不知道代表什么??还有我知道猜测到这段代码是解析request的url地址的,但是怎么解析却不是很懂,晕晕的,有高人能指点一下吗,不胜感激啊!!!
protected String processPath(HttpServletRequest request,
        HttpServletResponse response)
        throws IOException {
        String path;        // Set per request the original path for postback forms
        if (request.getAttribute(Globals.ORIGINAL_URI_KEY) == null) {
            request.setAttribute(Globals.ORIGINAL_URI_KEY, request.getServletPath());
        }        // For prefix matching, match on the path info (if any)
        path = (String) request.getAttribute(INCLUDE_PATH_INFO);        if (path == null) {
            path = request.getPathInfo();
        }        if ((path != null) && (path.length() > 0)) {
            return (path);
        }        // For extension matching, strip the module prefix and extension
        path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);        if (path == null) {
            path = request.getServletPath();
        }        String prefix = moduleConfig.getPrefix();        if (!path.startsWith(prefix)) {
            String msg = getInternal().getMessage("processPath");            log.error(msg + " " + request.getRequestURI());
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);            return null;
        }        path = path.substring(prefix.length());        int slash = path.lastIndexOf("/");
        int period = path.lastIndexOf(".");        if ((period >= 0) && (period > slash)) {
            path = path.substring(0, period);
        }        return (path);
    }

解决方案 »

  1.   

    Globals.ORIGINAL_URI_KEY,INCLUDE_PATH_INFO,INCLUDE_SERVLET_PATH这些都是配置文件中定义的字符串常量,它们的值你可以随意定义,不过是不能更改的,你可以把它们理解为final类型的变量,这段代码就是判断url地址是不是以指定的字符串开头,如果不是就把错误写入log日志,如果是的话,就截取其中的某段地址并返回