怎样配置才能使struts中的*.do 映射 去掉 .do ,直接用没有后缀名的映射
1.一直想用struts弄成没有后缀名的请求,跟javaeye的一样,今天看了下struts的源代码,发现
它截取的是最后一个/和最后一个.之间的字符串当做struts-config.xml里配的action。如:
<servlet-mapping> <servlet-name>action</servlet-name> <!-- <url-pattern>/usermgr/*</url-pattern> --> <url-pattern>/</url-pattern> </servlet-mapping>
public class LoginAction extends Action
<!--用于定义RequestProcessor类它截取URI最后一个/后面的字符串,就当做action --><controller processorname="code">public class allController extends RequestProcessor{@Overrideprotected String processPath(HttpServletRequest request,HttpServletResponse response) throws IOException {// TODO Auto-generated method stub 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("."); path = path.substring(0);System.out.println(path); return (path);}}{ 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); }