浜岋細ActionServlet鍒嗘瀽
鎴戜滑鍏堟潵鐪嬩竴涓嬩嬌鐢⊿truts鐨勯厤緗枃浠躲?/p>
action
org.apache.struts.action.ActionServlet
definitions-config
/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-tests-defs.xml,/WEB-INF/tiles-tutorial-defs.xml,
/WEB-INF/tiles-examples-defs.xml
definitions-debug
0
definitions-parser-details
0
definitions-parser-validate
true
聽
config
/WEB-INF/struts-config.xml
聽
config/examples
/WEB-INF/struts-examples-config.xml
聽
config/test
/WEB-INF/struts-tests-config.xml
聽
config/tutorial
/WEB-INF/struts-tutorial-config.xml
validate
true
debug
2
detail
2
聽
application
org.apache.struts.webapp.tiles.dev1-1.ApplicationResources
2
聽
action
*.do
聽
鎺ヤ笅鏉ユ垜浠潵鐪嬩竴涓婣ctionServlet鐨勫叿浣撲嬌鐢?br />javax.servlet.http.HttpServlet
|
|-->org.apache.struts.action.ActionServlet
鎵浠ユ湰璐ㄤ笂ActionServlet鏄竴涓櫘閫氱殑servlet錛岃礋璐e鐞?do涓哄悗緙鐨凥ttp璇鋒眰.
servlet鍦ㄦ墽琛宒oGet(),doPost(),涔嬪墠鍏堣皟鐢╥nit(),
浠ヤ笅鎴戜滑鍏堝垎鏋愪竴涓媔nit()鏂規硶
/**
* Initialize this servlet. Most of the processing has been factored into
* support methods so that you can override particular functionality at a
* fairly granular level.
* servlet鍒濆鍖栨搷浣?娉ㄦ剰鍒濆鍖栭『搴?br />* @exception ServletException if we cannot configure ourselves correctly
*/
public void init() throws ServletException {
//娉ㄦ剰鍒濆鍖栫殑欏哄簭
//Initialize our internal MessageResources bundle
initInternal();
//Initialize other global characteristics of the controller servlet
//澶勭悊涓浜涘叏灞鍙橀噺鐨勮緗錛歞ebug錛宒etail絳?br />initOther();
//Initialize the servlet mapping under which our controller servlet
//is being accessed. This will be used in the &html:form>
//tag to generate correct destination URLs for form submissions
//涓昏鏄敞鍐孌TD鏂囦歡浠ュ強瑙f瀽web.xml鍏充簬ActionServlet鐨勯厤緗傚鍚庣紑鍚嶇瓑.
// Configure the processing rules that we need
// digester.addCallMethod("web-app/servlet-mapping",
// "addServletMapping", 2);
// digester.addCallParam("web-app/servlet-mapping/servlet-name", 0);
// digester.addCallParam("web-app/servlet-mapping/url-pattern", 1);
//initServlet()鐨勪笂闈竴孌靛皢鎶奡truts榛樿鐨勫悗緙鍚嶄粠web.xml涓В鏋愬緱鍒?br />//涔熷氨鏄痺eb.xml涓殑濡備笅閰嶇疆錛?br />//
//action
//*.do
//榛樿浠?do緇撳熬鐨勮姹傞兘灝嗙敱Struts鏉ュ鐞嗭紝浣犲彲浠ヨ嚜宸變慨鏀?br />//
initServlet();
// Initialize modules as needed
//鍦ˋttribute涓繚瀛樼被瀹炰緥
getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
//鏍規嵁閰嶇疆鏂囦歡鐢熸垚ModuleConfig,榪欐槸寰堥噸瑕佺殑涓姝?涓嬮潰浼氫笓闂ㄥ垎鏋?br />//鍦╰iles鐨勯厤緗腑鍏堣В鏋愭敞閲婁負"Mark 0"鐨勪竴涓厤緗枃浠?/WEB-INF/struts-config.xml
//浣跨敤initModuleConfig鏂規硶瑙f瀽XML鏂囦歡.
//鍙傛暟涓簆refix錛?",paths:"/WEB-INF/struts-config.xml"
ModuleConfig moduleConfig = initModuleConfig("", config);
//鍒濆鍖朚essage
initModuleMessageResources(moduleConfig);
//鍒濆鍖朖DBC DataSource
initModuleDataSources(moduleConfig);
//鍒濆鍖朠lunIn
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
//鍦⊿truts1.1浠ュ悗鍙互浣跨敤澶氫釜閰嶇疆鏂囦歡,鍦ㄨВ鏋愬畬榛樿鐨勯厤緗枃浠朵篃灝辨槸涓婇潰鎻愬埌鐨?br />//娉ㄩ噴涓?Mark 0"鐨勪竴涓厤緗枃浠?/WEB-INF/struts-config.xml鍚庤В鏋愬叾浠栫殑閰嶇疆鏂囦歡
Enumeration names = getServletConfig().getInitParameterNames();
//渚濇瑙f瀽娉ㄩ噴涓?Mark 1"銆?Mark 2"銆?Mark 3"瀵瑰簲閰嶇疆鏂囦歡
while (names.hasMoreElements()) {
//姣忎竴涓厤緗枃浠剁殑鏂囦歡鍚?br />String name = (String) names.nextElement();
if (!name.startsWith("config/")) {
continue;
}
//
String prefix = name.substring(6);
moduleConfig = initModuleConfig
(prefix, getServletConfig().getInitParameter(name));
initModuleMessageResources(moduleConfig);
initModuleDataSources(moduleConfig);
initModulePlugIns(moduleConfig);
moduleConfig.freeze();
}
destroyConfigDigester();
}
/**
* 姝ゆ柟娉曚嬌鐢―igester瑙f瀽XML,鍏充簬浣跨敤Digester鐨勪粙緇嶅弬鐪嬫垜鐨勫彟澶栦竴綃囨枃绔?br />*
Initialize the application configuration information for the
* specified module.
*
* @param prefix Module prefix for this module
* @param paths Comma-separated list of context-relative resource path(s)
* for this modules's configuration resource(s)
*
* @exception ServletException if initialization cannot be performed
* @since Struts 1.1
*/
protected ModuleConfig initModuleConfig
(String prefix, String paths) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + prefix +
"' configuration from '" + paths + "'");
}
// Parse the configuration for this module
ModuleConfig config = null;
InputStream input = null;
String mapping = null;
try {
//宸ュ巶鏂規硶鍒涘緩ModuleConfig鏍囪涓猴細prefix
ModuleConfigFactory factoryObject =
ModuleConfigFactory.createFactory();
config = factoryObject.createModuleConfig(prefix);
// Support for module-wide ActionMapping type override
mapping = getServletConfig().getInitParameter("mapping");
if (mapping != null) {
config.setActionMappingClass(mapping);
}
// Configure the Digester instance we will use
//寰楀埌瑙f瀽XML鐨刣igester
Digester digester = initConfigDigester();
// Process each specified resource path
while (paths.length() > 0) {
//寮濮嬭В鏋愭寚瀹氳礬寰勬枃浠跺悕鐨勬枃浠?br />digester.push(config);
String path = null;
//鏂囦歡鏄惁涓哄涓茍涓斾嬌鐢?,"鍒嗗壊
int comma = paths.indexOf(',');
//瀛樺湪澶氫釜閰嶇疆鏂囦歡
if (comma >= 0) {
//鍏堣В鏋愮涓涓?br />path = paths.substring(0, comma).trim();
//paths瀛樻斁鍓╀綑鐨勬枃浠跺悕涓嬫鍐嶅鐞?br />paths = paths.substring(comma + 1);
} else {
//褰撳墠鍙瓨鍦ㄤ竴涓?br />path = paths.trim();
//娌℃湁鍓╀綑,涓嬫寰幆鏍規嵁涓婇潰涓鍙ュ皢浼氬湪鍞竴鐨勫驚鐜鍑虹偣"point break"
//閫鍑哄驚鐜?br />paths = "";
}
//鍏ㄩ儴瑙f瀽瀹屾垚璺沖嚭寰幆
//point break
if (path.length() < 1) {
break;
}
//鏍規嵁鏂囦歡鍚嶅彇鏂囦歡
URL url = getServletContext().getResource(path);
InputSource is = new InputSource(url.toExternalForm());
input = getServletContext().getResourceAsStream(path);
is.setByteStream(input);
digester.parse(is);
//鍏ㄥ眬鍙橀噺鐨勫艦寮忔妸瑙f瀽鐢熸垚鐨凪oduleConfig瀹炰緥淇濆瓨璧鋒潵
//濡?Mark 1"澶勬爣璁扮殑"config/examples",
//key涓猴細"org.apache.struts.action.MODULEexamples"
//Globals.MODULE_KEY鍊間負:org.apache.struts.action.MODULE
getServletContext().setAttribute
(Globals.MODULE_KEY + prefix, config);
input.close();
}
} catch (Throwable t) {
log.error(internal.getMessage("configParse", paths), t);
throw new UnavailableException
(internal.getMessage("configParse", paths));
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
;
}
}
}
// Force creation and registration of DynaActionFormClass instances
// for all dynamic form beans we wil be using
//鏍規嵁ModuleConfig瀹炰緥寰楀埌閰嶇疆鐨凢ormBean鐨勯厤緗?br />//娉ㄦ剰錛氬洜涓哄湪Struts鏁翠釜榪愯褰撲腑FormBean鐨勫疄渚嬭鍦ˋction鐨勫疄渚嬪垱寤轟箣鍓嶅厛鍒涘緩
//鍥犱負Action鎵цperform(1.1浠ュ墠)錛宔xecute錛?.1錛夐渶瑕佷嬌鐢ㄥ埌FormBean
FormBeanConfig fbs[] = config.findFormBeanConfigs();
for (int i = 0; i < fbs.length; i++) {
if (fbs[i].getDynamic()) {
DynaActionFormClass.createDynaActionFormClass(fbs[i]);
}
}
// Special handling for the default module (for
// backwards compatibility only, will be removed later)
//涓嬮潰鏄敓鎴愪竴浜涘疄渚?br />if (prefix.length() < 1) {
defaultControllerConfig(config);
defaultMessageResourcesConfig(config);
defaultFormBeansConfig(config);
defaultForwardsConfig(config);
defaultMappingsConfig(config);
}
// Return the completed configuration object
//config.freeze(); // Now done after plugins init
return (config);
}
鍒版鍒濆鍖栧伐浣滃熀鏈粨鏉燂紝涓嬮潰灝嗗鐞嗗叿浣撶殑Http璇鋒眰銆傚湪Servlet鍗忚涓墍鏈夌殑post鏂規硶灝嗚皟鐢?br />浠ヤ笅鏂規硶鏉ュ鐞?br />public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {}
get鏂規硶涔熻皟鐢ㄧ被浼肩殑鏂規硶鏉ュ鐞?
鍦⊿truts涓璸ost,get鏂規硶閮借皟鐢ㄥ悓涓涓柟娉?br />process(request, response);鏉ュ鐞嗗叿浣撶殑璇鋒眰
濡備笅錛?br />/**
* 瀵規瘡涓涓彁浜よ繃鏉ョ殑Action榪涜澶勭悊
* Perform the standard request processing for this request, and create
* the corresponding response.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception is thrown
*/
protected void process(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
//璁劇疆鎴栧垹闄ttribute
RequestUtils.selectModule(request, getServletContext());
//鍏蜂綋鐨勫鐞嗕氦緇橰equestProcessor鍘誨鐞咹ttpRequest,HttpResponse
//榪欐槸涓涓緢鍏稿瀷鐨勮璁℃ā寮?br />//涓嬮潰鎴戜滑灝嗚緇嗘潵鍒嗘瀽RequestProcessor錛屽緢瀹規槗鐞嗚ВStruts鐨勮繍琛屾柟寮?br />getRequestProcessor(getModuleConfig(request)).process(request, response);
}
涓?RequestProcessor鍒嗘瀽
閫氳繃鍓嶉潰鐨勫垎鏋愭垜浠煡閬揝truts涓HttpRequest,HttpResponse鐨勫鐞嗛兘浜ょ粰RequestProcessor
鐨刾rocess錛堬級鏂規硶鏉ュ鐞嗐備笅闈㈡垜浠潵鐪嬬湅process鏂規硶
/**
*
Process an HttpServletRequest and create the
* corresponding HttpServletResponse.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a processing exception occurs
*/
public void process(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Wrap multipart requests with a special wrapper
//濡傛灉鏄痷pload,榪斿洖涓涓狹ultipartRequestWrapper()
request = processMultipart(request);
// Identify the path component we will use to select a mapping
//瀵箁equest榪涜鍒嗘瀽寰楀埌鎻愪氦榪囨潵鐨凢orm Action
String path = processPath(request, response);
if (path == null) {
return;
}
if (log.isInfoEnabled()) {
log.info("Processing a '" + request.getMethod() +
"' for path '" + path + "'");
}
// Select a Locale for the current user if requested
//鏈湴鍖栧鐞?br />processLocale(request, response);
// Set the content type and no-caching headers if requested
processContent(request, response);
//璁劇疆Cache涓嶄繚瀛?br />processNoCache(request, response);
// General purpose preprocessing hook
if (!processPreprocess(request, response)) {
return;
}
// Identify the mapping for this request
//寰楀埌path浠ュ悗錛屾牴鎹厤緗枃浠?struts-config.xml)鐨勭浉鍏抽厤緗潵寰楀埌涓涓?br />//ActionMapping鐨勫疄渚?br />//ActionMapping緇ф壙ActionConfig
//浠旂粏鐪嬩竴涓婣ctionMapping鐨勪唬鐮佸氨鑳藉彂鐜幫細
//涓嬮潰鐨勪竴孌靛皢瑙f瀽褰卞皠涓涓狝ctionMapping鐨勫疄渚?br />//鍦ˋctionServlet鍦ㄥ垵濮嬪寲鐨勬椂鍊欏疄闄呬笂宸茬粡鎶婃墍鏈夌殑ActionMapping鐨勫疄渚?br />//閮藉凡緇忓垱寤哄ソ浜嗐俻rocessMapping鏂規硶瀹為檯涓婃槸浠嶢ttribute涓幓寰楀埌宸茬粡
//淇濆瓨濂界殑ActionMapping鐨勫疄渚嬶紝鍙互鐞嗚В涓哄湪Tomcat鍚姩鐨勬椂鍊欏凡緇?br />//鎶婃墍鏈夌殑ActionMapping淇濆瓨鍦ˋttribute閲岄潰銆傛墍浠ュ湪Tomcat鍚姩鐨勬椂鍊?br />//姣旇緝鎱紝濡傛灉Struts-config.xml鏈夐棶棰樺惎鍔ㄥ氨浼氬嚭閿欍?br />/***
type="org.apache.struts.webapp.tiles.test.TestActionTileAction">
聽
**/
//****娉ㄦ剰寰楀埌鍒涘緩瀹炰緥鐨勯『搴?br />//ActionMapping瀹炰緥宸茬粡鍒涘緩濂戒簡錛岀幇鍦ㄤ粠Atribute涓彇鍒?br />ActionMapping mapping = processMapping(request, response, path);
if (mapping == null) {
return;
}
// Check for any role required to perform this action
if (!processRoles(request, response, mapping)) {
return;
}
// Process any ActionForm bean related to this request
//鏍規嵁mapping寰楀埌ActionForm鐨勫疄渚嬨?br />//鍚屽悕ActionForm鍦ㄧ郴緇熶腑鍙細鍒涘緩涓嬈°?br />ActionForm form = processActionForm(request, response, mapping);
//鍘嬫爤
processPopulate(request, response, form, mapping);
//澶勭悊鏍¢獙,璋冪敤ActionForm鐨剉alidate鏂規硶
//鍋囧鍑洪敊灝嗕細榪斿洖鍒板墠涓欏甸潰
//涔熷氨鏄鍦ˋction榪樻病鏈夊垱寤轟箣鍓嶅氨灝嗗仛鏍¢獙
if (!processValidate(request, response, form, mapping)) {
return;
}
// Process a forward or include specified by this mapping
if (!processForward(request, response, mapping)) {
return;
}
if (!processInclude(request, response, mapping)) {
return;
}
// Create or acquire the Action instance to process this request
//鍦ㄥ緱鍒癆ctionMapping銆丄ctionForm鐨勫疄渚嬪悗鎺ヤ笅鏉ュ緱鍒癆ction瀹炰緥
//瀹炰緥濡傛灉宸茬粡鍒涘緩浠嶮ap閲岄潰鍘誨彇濡傛灉娌℃湁鍒涘緩涓涓茍淇濆瓨鍦∕ap閲岄潰
//瀵逛繚瀛楢ction瀹炰緥鐨凪ap 瀹炵幇綰跨▼鍚屾
Action action = processActionCreate(request, response, mapping);
if (action == null) {
return;
}
// Call the Action instance itself
//鍦ˋctionMapping銆丄ctionForm銆丄ction瀹炰緥鍒涘緩濂戒互鍚?br />//璋冪敤Action鐨別xecute()鏂規硶寰楀埌涓涓狝ctionForward
//鍥犱負鎵鏈夌殑鍙墽琛孉ction閮藉繀欏繪湁override Action鐨別xecute()/perform()鏂規硶
ActionForward forward =
processActionPerform(request, response,
action, form, mapping);
// Process the returned ActionForward instance
//Action宸茬粡姝e父鎵ц錛屾墽琛岀粨鏉熷悗灝嗚繑鍥炲埌鍙﹀涓涓〉闈?br />processActionForward(request, response, forward);
}
浠旂粏闃呰涓婇潰鐨勪唬鐮侊紝瑕佺壒鍒敞鎰廇ctionMapping銆丄ctionForm銆丄ction鐨勫疄渚嬫槸渚濇鍒涘緩鐨勩?br />鍒涘緩瀹屼互鍚庢墠鍘繪墽琛孉ction鐨別xecute()鏂規硶銆備負浠涔堣渚濇鍒涘緩ActionMapping銆丄ctionForm
銆丄ction??????
鍥?ModuleConfig鍒嗘瀽
鐜板湪鎴戜滑寰堟湁蹇呰浜嗚В涓涓婱oduleConfig榪欎釜綾伙紝鍥犱負澶鍦版柟鐢ㄥ埌浜嗐?br />瀹為檯涓奙oduleConfig鏄竴涓帴鍙f湁涓涓疄鐜般俹rg.apache.struts.config.impl.ModuleConfigImpl
鍏蜂綋瀹炵幇鎴戝氨娌℃湁涓嶈鍘誨垎鏋愪簡銆傛垜浠潵鐪嬬湅榪欎釜鎺ュ彛銆?/p>
package org.apache.struts.config;
/**
*
The collection of static configuration information that describes a
* Struts-based module. Multiple modules are identified by
* a prefix at the beginning of the context
* relative portion of the request URI. If no module prefix can be
* matched, the default configuration (with a prefix equal to a zero-length
* string) is selected, which is elegantly backwards compatible with the
* previous Struts behavior that only supported one module.
*
* @author Rob Leland
* @version $Revision: 1.2 $ $Date: 2002/12/22 05:31:14 $
* @since Struts 1.1
*/
public interface ModuleConfig {
/**
* Has this module been completely configured yet. Once this flag
* has been set, any attempt to modify the configuration will return an
* IllegalStateException.
*/
boolean getConfigured();
/**
* The controller configuration object for this module.
*/
ControllerConfig getControllerConfig();
/**
* The controller configuration object for this module.
* @param cc The controller configuration object for this module.
*/
void setControllerConfig(ControllerConfig cc);
/**
* The prefix of the context-relative portion of the request URI, used to
* select this configuration versus others supported by the controller
* servlet. A configuration with a prefix of a zero-length String is the
* default configuration for this web module.
*/
String getPrefix();
/**
* The prefix of the context-relative portion of the request URI, used to
* select this configuration versus others supported by the controller
* servlet. A configuration with a prefix of a zero-length String is the
* default configuration for this web module.
*/
public void setPrefix(String prefix);
/**
* The default class name to be used when creating action mapping
* instances.
*/
String getActionMappingClass();
/**
* The default class name to be used when creating action mapping
* instances.
* @param actionMappingClass default class name to be used when creating action mapping
* instances.
*/
void setActionMappingClass(String actionMappingClass);
/**
* Add a new ActionConfig instance to the set associated
* with this module.
*
* @param config The new configuration instance to be added
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void addActionConfig(ActionConfig config);
/**
* Add a new DataSourceConfig instance to the set associated
* with this module.
*
* @param config The new configuration instance to be added
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void addDataSourceConfig(DataSourceConfig config);
/**
* Add a new ExceptionConfig instance to the set associated
* with this module.
*
* @param config The new configuration instance to be added
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void addExceptionConfig(ExceptionConfig config);
/**
* Add a new FormBeanConfig instance to the set associated
* with this module.
*
* @param config The new configuration instance to be added
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void addFormBeanConfig(FormBeanConfig config);
/**
* Add a new ForwardConfig instance to the set of global
* forwards associated with this module.
*
* @param config The new configuration instance to be added
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void addForwardConfig(ForwardConfig config);
/**
* Add a new MessageResourcesConfig instance to the set
* associated with this module.
*
* @param config The new configuration instance to be added
*
* @exception IllegalStateException if this module configuration
* has been frozen
*/
void addMessageResourcesConfig(MessageResourcesConfig config);
/**
* Add a newly configured {@link org.apache.struts.config.PlugInConfig} instance to the set of
* plug-in Actions for this module.
*
* @param plugInConfig The new configuration instance to be added
*/
void addPlugInConfig(PlugInConfig plugInConfig);
/**
* Return the action configuration for the specified path, if any;
* otherwise return null.
*
* @param path Path of the action configuration to return
*/
ActionConfig findActionConfig(String path);
/**
* Return the action configurations for this module. If there are
* none, a zero-length array is returned.
*/
ActionConfig[] findActionConfigs();
/**
* Return the data source configuration for the specified key, if any;
* otherwise return null.
*
* @param key Key of the data source configuration to return
*/
DataSourceConfig findDataSourceConfig(String key);
/**
* Return the data source configurations for this module. If there
* are none, a zero-length array is returned.
*/
DataSourceConfig[] findDataSourceConfigs();
/**
* Return the exception configuration for the specified type, if any;
* otherwise return null.
*
* @param type Exception class name to find a configuration for
*/
ExceptionConfig findExceptionConfig(String type);
/**
* Return the exception configurations for this module. If there
* are none, a zero-length array is returned.
*/
ExceptionConfig[] findExceptionConfigs();
/**
* Return the form bean configuration for the specified key, if any;
* otherwise return null.
*
* @param name Name of the form bean configuration to return
*/
FormBeanConfig findFormBeanConfig(String name);
/**
* Return the form bean configurations for this module. If there
* are none, a zero-length array is returned.
*/
FormBeanConfig[] findFormBeanConfigs();
/**
* Return the forward configuration for the specified key, if any;
* otherwise return null.
*
* @param name Name of the forward configuration to return
*/
ForwardConfig findForwardConfig(String name);
/**
* Return the form bean configurations for this module. If there
* are none, a zero-length array is returned.
*/
ForwardConfig[] findForwardConfigs();
/**
* Return the message resources configuration for the specified key,
* if any; otherwise return null.
*
* @param key Key of the data source configuration to return
*/
MessageResourcesConfig findMessageResourcesConfig(String key);
/**
* Return the message resources configurations for this module.
* If there are none, a zero-length array is returned.
*/
MessageResourcesConfig[] findMessageResourcesConfigs();
/**
* Return the configured plug-in actions for this module. If there
* are none, a zero-length array is returned.
*/
PlugInConfig[] findPlugInConfigs();
/**
* Freeze the configuration of this module. After this method
* returns, any attempt to modify the configuration will return
* an IllegalStateException.
*/
void freeze();
/**
* Remove the specified action configuration instance.
*
* @param config ActionConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeActionConfig(ActionConfig config);
/**
* Remove the specified exception configuration instance.
*
* @param config ActionConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeExceptionConfig(ExceptionConfig config);
/**
* Remove the specified data source configuration instance.
*
* @param config DataSourceConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeDataSourceConfig(DataSourceConfig config);
/**
* Remove the specified form bean configuration instance.
*
* @param config FormBeanConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeFormBeanConfig(FormBeanConfig config);
/**
* Remove the specified forward configuration instance.
*
* @param config ForwardConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeForwardConfig(ForwardConfig config);
/**
* Remove the specified message resources configuration instance.
*
* @param config MessageResourcesConfig instance to be removed
*
* @exception java.lang.IllegalStateException if this module configuration
* has been frozen
*/
void removeMessageResourcesConfig(MessageResourcesConfig config);
}
涓婇潰鐨勬敞閲婂凡緇忛潪甯告竻鏅頒簡銆傛垜灝變笉鍘繪氮璐瑰ぇ瀹剁殑鏃墮棿浜嗭紝鍐嶆兂浠旂粏鐪嬪氨鍘葷湅浠栫殑瀹炵幇銆?br />鍏跺疄涓昏鏄HashMap()鐨勫鐞嗐?/p>
浜旓細ActionMapping鍒嗘瀽
鏈鍚庢垜浠疄鐜板緢鏈夊繀瑕佺湅涓涓婣ctionMapping,鍥犱負浣犲鏋滄兂娓呮鐨勪簡瑙truts-config.xml
榪欎釜閰嶇疆鏂囦歡鐨勪綔鐢紝浣犲簲璇ヨ鐭ラ亾ActionMapping
鍓嶉潰宸茬粡璇磋繃ActionMapping緇ф壙ActionConfig
浠ヤ笅灝辨槸ActionMapping鍔犵殑鍥涗釜鏂規硶銆?br />/**
*
Find and return the ExceptionConfig instance defining
* how exceptions of the specified type should be handled. This is
* performed by checking local and then global configurations for the
* specified exception's class, and then looking up the superclass chain
* (again checking local and then global configurations). If no handler
* configuration can be found, return null.
*
* @param type Exception class for which to find a handler
* @since Struts 1.1
*/
public ExceptionConfig findException(Class type) {
}
/**
*
Find and return the ForwardConfig instance defining
* how forwarding to the specified logical name should be handled. This is
* performed by checking local and then global configurations for the
* specified forwarding configuration. If no forwarding configuration
* can be found, return null.
*
* @param name Logical name of the forwarding instance to be returned
*/
public ActionForward findForward(String name) {
}
/**
*
Return the logical names of all locally defined forwards for this
* mapping. If there are no such forwards, a zero-length array
* is returned.
*/
public String[] findForwards() {
}
/**
*
Create (if necessary) and return an {@link ActionForward} that
* corresponds to the input property of this Action.
*
* @since Struts 1.1b2
*/
public ActionForward getInputForward() {
}
榪樻槸鐪嬩互涓嬩粬鐨勫熀綾籄ctionConfig鍚?br />public class ActionConfig implements Serializable {
/**
* Has configuration of this component been completed?
*/
protected boolean configured = false;
/**
* The set of exception handling configurations for this
* action, if any, keyed by the type property.
*/
protected HashMap exceptions = new HashMap();
/**
* The set of local forward configurations for this action, if any,
* keyed by the name property.
*/
protected HashMap forwards = new HashMap();
/**
* The module configuration with which we are associated.
*/
protected ModuleConfig moduleConfig = null;
/**
* The request-scope or session-scope attribute name under which our
* form bean is accessed, if it is different from the form bean's
* specified name.
*/
protected String attribute = null;
/**
* Context-relative path of the web application resource that will process
* this request via RequestDispatcher.forward(), instead of instantiating
* and calling the Action class specified by "type".
* Exactly one of forward, include, or
* type must be specified.
*/
protected String forward = null;
/**
* Context-relative path of the web application resource that will process
* this request via RequestDispatcher.include(), instead of instantiating
* and calling the Action class specified by "type".
* Exactly one of forward, include, or
* type must be specified.
*/
protected String include = null;
/**
* Context-relative path of the input form to which control should be
* returned if a validation error is encountered. Required if "name"
* is specified and the input bean returns validation errors.
*/
protected String input = null;
/**
* Fully qualified Java class name of the
* MultipartRequestHandler implementation class used to
* process multi-part request data for this Action.
*/
protected String multipartClass = null;
/**
* Name of the form bean, if any, associated with this Action.
*/
protected String name = null;
/**
* General purpose configuration parameter that can be used to pass
* extra iunformation to the Action instance selected by this Action.
* Struts does not itself use this value in any way.
*/
protected String parameter = null;
/**
* Context-relative path of the submitted request, starting with a
* slash ("/") character, and omitting any filename extension if
* extension mapping is being used.
*/
protected String path = null;
/**
* Prefix used to match request parameter names to form ben property
* names, if any.
*/
protected String prefix = null;
/**
* Comma-delimited list of security role names allowed to request
* this Action.
*/
protected String roles = null;
/**
* Identifier of the scope ("request" or "session") within which
* our form bean is accessed, if any.
*/
protected String scope = "session";
/**
* Suffix used to match request parameter names to form bean property
* names, if any.
*/
protected String suffix = null;
/**
* Fully qualified Java class name of the Action class
* to be used to process requests for this mapping if the
* forward and include properties are not set.
* Exactly one of forward, include, or
* type must be specified.
*/
protected String type = null;
/**
* Should the validate() method of the form bean associated
* with this action be called?
*/
protected boolean validate = true;
}
鍏跺疄ActionConfig鏄竴涓緢鍏稿瀷鐨刅alueObject.鎵浠ュ叾浠栫殑get/set鏂規硶鎴戝氨涓嶅啓鍑烘潵浜嗐?br />鐪嬭繖涓唬鐮佷竴瀹氳鍜宻truts-config.xml涓璧鋒潵鐪嬶紝鏍規嵁struts-config.xml鍘繪壘鎵?br />姣忎竴孌甸厤緗枃浠舵渶緇堣鐢熸垚涓涓狝ctionConfig,浠栦滑涔嬮棿鐨勫搴斿叧緋匯?br />濡傛灉浣犳兂鎵╁睍Struts,ActionMapping浼拌浣犱竴瀹氳淇敼銆傝繕鏈堿ctionServlet浣犱篃瑕佷慨鏀廣?/p>
鍏細緇撴潫璇?br />鍒嗘瀽浜嗕竴浜涗唬鐮佷笅闈㈠仛涓浜涙榪般傚厛鏉ユ暣浣撶殑浜嗚В涓涓婼truts鐨勫伐浣滄祦紼?
鍦ㄥ疄鐜頒竴涓熀浜嶴truts鐨勮繍鐢ㄤ箣鍓嶆垜浠鍏堟槸鍋氱幆澧冭緗紝Struts姝e父宸ヤ綔闇瑕佽嚦灝戜袱涓?br />閰嶇疆鏂囦歡web.xml,struts-config.xml.
web.xml鍛婅瘔App Server鎵鏈変互.do緇撳熬鐨勮姹傛渶緇堟彁浜ょ粰ActionServlet鍘誨鐞嗐?br />2灝辮瀹欰ctionServlet鏄湪App Server鍚姩鐨勬椂鍊?br />鍒涘緩鐨勫茍涓斾竴鐩村瓨鍦ㄣ?br />ActionServlet鍦ㄥ垱寤虹殑鏃跺欎細鍋氬涓嬬殑宸ヤ綔錛?br />淇濆瓨涓浜涘悗闈㈤渶瑕佷嬌鐢ㄧ殑瀹炰緥鍦ˋttribute(鍐呭瓨)閲岄潰銆?br />鏍規嵁web.xml鐨勯厤緗В鏋恠truts-config.xml鏂囦歡銆?br />鏍規嵁struts-config.xml鐨勯厤緗敓鎴怉ctionMapping瀹炰緥騫朵笖淇濆瓨銆?/p>
ActionServlet鍦ㄧ敓鍛藉懆鏈熷氨涓鐩寸瓑寰匟ttp 璇鋒眰
姣忎竴涓?do緇撳熬鐨凥ttp 璇鋒眰閮界敱ActionServlet鍏堟埅鑾風劧鍚庢牴鎹姹傝礬寰勫緱鍒板叿浣撹皟鐢ㄩ偅
涓涓狝ction鍘誨鐞嗭紝鍦ㄨ繖涔嬪墠鐢熸垚銆佸鐞咥ctionForm銆傚叿浣撶煡閬撻偅涓涓狝ction鍘誨鐞嗚姹?br />鍚庤皟鐢ˋction鐨別xecute()/perform()澶勭悊瀹屾垚錛岃繑鍥炪?/p>
聽