struts1閲屼緷璧栫殑鏍稿績鎺у埗鍣ㄤ負ActionServlet鑰宻truts2渚濊禆ServletDispatcher,涓涓槸servlet涓涓槸filter,姝f槸閲囩敤浜唂ilter鎵嶄笉鑷充簬鍜宻ervlet鑰﹀悎錛屾墍鏈夌殑鏁版嵁 閮芥槸閫氳繃鎷︽埅鍣ㄦ潵瀹炵幇錛屽涓嬪浘鏄劇ず錛?/blockquote> 
- web灞傝〃鐜板眰鐨勪赴瀵岋紝struts2宸茬粡鍙互浣跨敤jsp銆乿elocity銆乫reemarker
- 綰跨▼妯″紡鏂歸潰錛歴truts1鐨刟ction鏄崟渚嬫ā寮忚屼笖蹇呴』鏄嚎紼嬪畨鍏ㄦ垨鍚屾鐨勶紝鏄痵truts2鐨刟ction瀵規(guī)瘡涓涓姹傞兘浜х敓涓涓柊鐨勫疄渚嬶紝鍥犳娌℃湁綰跨▼瀹夊叏闂? 棰樸?/li>
- 灝佽璇鋒眰鍙傛暟錛氭槸struts1閲囩敤ActionForm灝佽璇鋒眰鍙傛暟錛岄兘蹇呴』緇ф壙ActionForm鍩虹被錛岃宻truts2閫氳繃bean鐨勫睘鎬у皝瑁咃紝澶уぇ闄嶄綆浜嗚﹀悎銆?/li>
- 綾誨瀷杞崲錛歴truts1灝佽鐨凙ctionForm閮芥槸String綾誨瀷錛岄噰鐢–ommons- Beanutils榪涜綾誨瀷杞崲錛屾瘡涓被涓涓漿鎹㈠櫒錛泂truts2閲囩敤OGNL榪涜綾誨瀷杞? 鎹紝鏀寔鍩烘湰鏁版嵁綾誨瀷鍜屽皝瑁呯被鍨嬬殑鑷姩杞崲銆?/li>
- 鏁版嵁鏍¢獙錛歴truts1鍦ˋctionForm涓噸鍐檝alidate鏂規(guī)硶錛泂truts2鐩存帴閲嶅啓validate鏂規(guī)硶錛岀洿鎺ュ湪action閲岄潰閲嶅啓鍗沖彲錛屼笉闇瑕佺戶鎵夸換浣曞熀綾伙紝瀹為檯鐨勮皟鐢ㄩ『搴忔槸錛寁alidate()-->execute()錛屼細鍦ㄦ墽琛宔xecute涔嬪墠璋冪敤validate,涔熸敮鎸亁work鏍¢獙妗嗘灦鏉ユ牎楠屻?/li>
鍏舵錛岃涓涓嬩負浠涔堣閲囩敤webwork鏉ラ噸鏂拌璁truts2
棣栧厛鐨勪粠鏍稿績鎺у埗鍣ㄨ皥璧鳳紝struts2鐨凢ilterDispatcher錛岃繖閲屾垜浠煡閬撴槸涓涓猣ilter鑰屼笉鏄竴涓猻ervlet,璁插埌榪欓噷寰堝浜鴻繕涓嶆槸寰堟竻妤歸eb.xml閲屽畠浠箣闂寸殑鑱旂郴錛屽厛綆鐭涓涓嬪畠浠殑鍔犺澆欏哄簭錛宑ontext-param(搴旂敤鑼冨洿鐨勫垵濮嬪寲鍙傛暟)-->listener(鐩戝惉搴旂敤绔殑浠諱綍淇敼閫氱煡)-->filter(榪囨護)-->servlet銆?br /> filter鍦ㄦ墽琛宻ervlet涔嬮棿灝變互鍙婅皟鐢ㄤ簡錛屾墍浠ユ墠鏈夊彲鑳借В鑴卞畬鍏ㄤ緷璧杝ervlet鐨勫眬闈紝閭f垜浠潵鐪嬬湅榪欎釜filter鍋氫簡浠涔堜簨鎯咃細
/** * Process an action or handle a request a static resource.
* <p/>
* The filter tries to match the request to an action mapping.
* If mapping is found, the action processes is delegated to the dispatcher's serviceAction method.
* If action processing fails, doFilter will try to create an error page via the dispatcher.
* <p/>
* Otherwise, if the request is for a static resource,
* the resource is copied directly to the response, with the appropriate caching headers set.
* <p/>
* If the request does not match an action mapping, or a static resource page,
* then it passes through.
*
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
ServletContext servletContext = getServletContext();
String timerKey = "FilterDispatcher_doFilter: ";
try {
// FIXME: this should be refactored better to not duplicate work with the action invocation
ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack();
ActionContext ctx = new ActionContext(stack.getContext());
ActionContext.setContext(ctx);
UtilTimerStack.push(timerKey);
request = prepareDispatcherAndWrapRequest(request, response);
ActionMapping mapping;
try {
mapping = actionMapper.getMapping(request, dispatcher.getConfigurationManager());
} catch (Exception ex) {
log.error("error getting ActionMapping", ex);
dispatcher.sendError(request, response, servletContext, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
return;
}
if (mapping == null) {
// there is no action in this request, should we look for a static resource?
String resourcePath = RequestUtils.getServletPath(request);
if ("".equals(resourcePath) && null != request.getPathInfo()) {
resourcePath = request.getPathInfo();
}
if (staticResourceLoader.canHandle(resourcePath)) {
staticResourceLoader.findStaticResource(resourcePath, request, response);
} else {
// this is a normal request, let it pass through
chain.doFilter(request, response);
}
// The framework did its job here
return;
}
dispatcher.serviceAction(request, response, servletContext, mapping);//榪囨護鐢ㄦ埛璇鋒眰錛屾嫤鎴櫒鎵ц錛屾妸瀵瑰簲鐨刟ction璇鋒眰杞埌涓氬姟action鎵ц }
finally {
try {
ActionContextCleanUp.cleanUp(req);
} finally {
UtilTimerStack.pop(timerKey);
}
}
}
瀵瑰簲鐨刟ction鍙傛暟鐢辨嫤鎴櫒鑾峰彇銆?br /> 瑙hervlet鏄痵truts2閲囩敤webwork鎬濊礬鐨勬渶閲嶈鐨勪竴涓師鍥狅紝涔熻繋鍚堜簡鏁翠釜鎶鏈殑涓涓彂灞曟柟鍚戯紝瑙h︿竴鐩磋瘡絀夸簬鏁翠釜妗嗘灦銆?/span>

]]>