锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一本大道在线,99热99re6国产在线播放,中文字幕一区二区三区久久网站http://www.aygfsteel.com/dont-bird-me/articles/struts.htmllalalalaThu, 13 Dec 2007 16:44:00 GMThttp://www.aygfsteel.com/dont-bird-me/articles/struts.htmlhttp://www.aygfsteel.com/dont-bird-me/comments/167631.htmlhttp://www.aygfsteel.com/dont-bird-me/articles/struts.html#Feedback0http://www.aygfsteel.com/dont-bird-me/comments/commentRss/167631.htmlhttp://www.aygfsteel.com/dont-bird-me/services/trackbacks/167631.html鏈枃鎸夌収1.鏋勯犲嚱鏁?>2.init()->3.do*()->4.destroy()鐨勯『搴忥紝瑙f瀽ActionServlet鐨勫伐浣滃師鐞嗐?br />
init()鐨勫垵濮嬪寲宸ヤ綔鍒嗕負涓楠よ繘琛岋細
1.initInternal()璧勬簮鏂囦歡鐨勫垵濮嬪寲
protected String internalName = "org.apache.struts.action.ActionResources";

protected void initInternal()
{
internal = MessageResources.getMessageResources(internalName);//鍒濆鍖栬祫婧愭枃浠朵俊鎭紝閫氳繃宸ュ巶妯″紡鍙栧緱涓涓崟渚嬬殑璧勬簮
}
internalName涓巌nitInternal()閮芥槸protected鎵浠ュ彲浠ヨ瀛愮被閲嶈澆銆備慨鏀箂truts榛樿鐨勮祫婧愭枃浠朵俊鎭?br />
2.initOther()鏍規嵁web.xml鐨勯厤緗弬鏁版墽琛屼笉鍚岀殑鍒濆鍖?1.璁劇疆struts閰嶇疆鏂囦歡璺緞2.convertNull

protected void initOther()throws ServletException
{
String value;
value = getServletConfig().getInitParameter("config");

if (value != null)
{
config = value; //璁劇疆struts閰嶇疆鏂囦歡璺緞
}
value = getServletConfig().getInitParameter("convertNull");
if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value)
|| "on".equalsIgnoreCase(value) || "y".equalsIgnoreCase(value)

|| "1".equalsIgnoreCase(value))
{
convertNull = true;
}

if (convertNull)
{ //濡傛灉convertNull涓簍rue\on\yes\y\1鎵ц
ConvertUtils.deregister();
ConvertUtils.register(new BigDecimalConverter(null),BigDecimal.class);
……
}
}

3.initServlet()瑙f瀽servletName,url-Pattern銆傚畼鏂箂truts鐨剋eb.xml錛歴ervletName=action,urlPattern=/*.do

protected void initServlet()throws ServletException
{
this.servletName = getServletConfig().getServletName();//鍙栧緱璁劇疆servletName

/**//*digester涓昏鏄疄鐜板xml鐨勮闂紝璁稿鍔熻兘寮哄ぇ鐨勫父鐢ㄦ搷浣滈兘宸茬粡灝佽浜嗚搗鏉ャ?/span>*/
Digester digester = new Digester();
digester.push(this);
digester.setNamespaceAware(true);
digester.setValidating(false);

for (int i = 0; i < registrations.length; i += 2)
{
URL url = this.getClass().getResource(registrations[i + 1]);

if (url != null)
{
digester.register(registrations[i], url.toString());
}
}

/**//*浠ヤ笅3鍙ョ殑鎰忔濇槸褰撻亣鍒皐eb-app/servlet-mapping鏃舵墽琛宎ddServletMapping鍑芥暟(涓嬮潰鏈夎鍑芥暟鐨勬簮鐮?錛岃繖涓柟娉曟湁涓や釜鍙傛暟錛岀涓涓槸web-app/servlet-mapping/servlet-name鏍囩閲岀殑錛岀浜屼釜鏄痺eb-app/servlet-mapping/url-pattern鏍囩閲岀殑.parse (input)寮濮嬭В鏋愩傚疄闄呬笂榪欐闄岀敓鐨勪唬鐮佸彧鏄墽琛屼簡addServletMapping(servlet-name,url-pattern);servlet-name,url-pattern鍒嗗埆浠?WEB-INF/web.xml涓彇寰?/span>*/
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);
InputStream input =
getServletContext().getResourceAsStream("/WEB-INF/web.xml");
digester.parse(input);

if (servletMapping != null)
{
getServletContext().setAttribute(Globals.SERVLET_KEY, servletMapping);
}
}



/**//*鍦╥nitServlet()涓璋冪敤*/

public void addServletMapping(String servletName, String urlPattern)
{

if (servletName == null)
{
return;
}

/**//*涓鑸岃█servletName=action,urlPattern=/*.do*/

if (servletName.equals(this.servletName))
{

if (log.isDebugEnabled())
{
log.debug("Process servletName=" + servletName
+ ", urlPattern=" + urlPattern);
}

this.servletMapping = urlPattern;
}
}
(鍒濆鍖栧伐浣滆繕鏈畬鎴?寰呯畫)

]]>- ActionServlet(1)http://www.aygfsteel.com/dont-bird-me/articles/ActionServlet1.htmllalalalaWed, 12 Dec 2007 17:18:00 GMThttp://www.aygfsteel.com/dont-bird-me/articles/ActionServlet1.htmlhttp://www.aygfsteel.com/dont-bird-me/comments/167365.htmlhttp://www.aygfsteel.com/dont-bird-me/articles/ActionServlet1.html#Feedback0http://www.aygfsteel.com/dont-bird-me/comments/commentRss/167365.htmlhttp://www.aygfsteel.com/dont-bird-me/services/trackbacks/167365.html
鍦ㄩ」鐩紑鍙戜腑錛孉ctionServlet鐨勫嚭鐜版渶灝戝彧闇瑕?嬈★紝渚挎槸鍦╳eb.xml涓?br />
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
涓嶇煡閬撹澶嶅埗浜嗗灝戦亶鐨勪竴孌典唬鐮侊紝浠婂ぉ鎴戠粓浜庣嫚涓嬪績瑕佹潵鎻紑浠栫殑縐樺瘑錛?br />
ActionServlet緇ф壙浜嶩ttpServlet錛屾墍浠ュ彲浠ュ畨鍏ㄧ殑鏀懼湪web.xml鐨?lt;/servlet-clss>鏍囩閲屻傚湪鍘熷鐨刯ava web寮鍙戜腑錛孒ttpServlet鐨刬nit()\destroy() \service() \do*()鍑芥暟緇忓父闇瑕佹牴鎹笟鍔$戶鎵垮疄鐜般傚悓鏍風殑錛屽湪ActionServlet閲岋紝瀹冪戶鎵垮疄鐜頒簡榪欏嚑涓柟娉曪紝浠庤繖涓剰涔変笂璁睞ctionServlet涓庡師濮媤eb寮鍙戜腑鐨剆ervlet娌℃湁浠諱綍鐨勫尯鍒?br />
ActionServlet灝辨槸涓涓狧ttpServlet鐨勭壒孌婂疄鐜幫紝鎵浠ヨ鐪熸浜嗚ВActionServlet嫻佺▼蹇呴』鐭ラ亾HttpServlet鐨勬祦紼嬨?br />
HttpServlet鐨勬祦紼嬪簲璇ュ寘鎷細1.鏋勯犲嚱鏁?>2.init()->3.do*()->4.destroy()銆?br />
init()鐨勬墽琛屾椂闂存湁涓ょ鏂瑰紡:1.Tomcat鍚姩鏃?.鍦ㄦ彁浜ゅ埌璇ervlet鏃?錛堝彲浠ラ氳繃<load-on-startup>榪涜璁劇疆錛?br />
鍚屾牱鐨勫湪ActionServlet涓紝涔熸槸鐢辮繖鍑犱釜鍑芥暟鏉ユ槸瀹炵幇web鏈嶅姟鐨勶紝鍙槸瀹冩墍瀹炵幇鐨勫茍涓嶆槸涓氬姟鏈嶅姟浠g爜錛岃屾槸鎺у埗浠g爜銆?nbsp;

]]> - 涓涓猄ingleton鐨勯棶棰?!help!!http://www.aygfsteel.com/dont-bird-me/articles/SingletonMemberField.htmllalalalaFri, 07 Dec 2007 16:56:00 GMThttp://www.aygfsteel.com/dont-bird-me/articles/SingletonMemberField.htmlhttp://www.aygfsteel.com/dont-bird-me/comments/166181.htmlhttp://www.aygfsteel.com/dont-bird-me/articles/SingletonMemberField.html#Feedback3http://www.aygfsteel.com/dont-bird-me/comments/commentRss/166181.htmlhttp://www.aygfsteel.com/dont-bird-me/services/trackbacks/166181.html 鏈榪戝湪鍋氫竴浜涗唬鐮佸畨鍏ㄦф鏌ワ紝浣跨敤浜咶ortify銆傚彂鐜頒簡涓浜涙浘緇忓紩浠ヤ負璞殑浠g爜鏃㈢劧浼氬嚭鐜伴珮鍗辯殑閿欒銆傚笇鏈涘悇浣嶈揪浜虹粰浜堝府鍔┿?br />
璁捐鍒濊》:鍏變韓WebApplicationContext,閫氳繃getBean(String beanName)鍙栧緱瀵瑰簲鐨刡ean澶勭悊鐩稿簲鐨勪笟鍔¢昏緫銆?

public class BaseAction extends Action
{
private WebApplicationContext wac;
protected ServletContext context;

public void setServlet(ActionServlet actionServlet)
{
super.setServlet(actionServlet);
context = actionServlet.getServletContext();
wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
}


protected Object getBean(String beanName)
{
return wac.getBean(beanName);
}
}
楂樺嵄閿欒浠g爜錛?/span>
context = actionServlet.getServletContext();
wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

閿欒鍘熷洜鍒嗘瀽錛欱aseAction緇ф壙鑷狝ction,鍗曚緥瀹炵幇銆傝綾誨惈鏈夊睘鎬э細wac涓巆ontext錛屽湪澶氱嚎紼嬬幆澧冧笅涓嶈兘淇濊瘉榪欎袱涓睘鎬х殑鍚堢悊閫昏緫銆備簬鏄帀鍏ヤ簡涓涓崟渚嬫ā寮忕殑闄烽槺銆傦紙璇峰悇浣嶈揪浜哄畬鍠勶級
瑙e喅鏂規硶錛歫don(banq)緇欐垜鐨勫洖澶?nbsp;
banq:鍐欑殑鏂規硶鏄珮鍗憋紝浣嗘槸鐪嬩綘鐨勬柟娉曞唴瀹癸紝鍒欐病鏈夊叧緋匯?br />
浣犵殑鏂規硶鍐呭鏄幏寰椾竴涓猈eb欏圭洰鐨勪竴涓崟渚嬶紝瀹為檯灝辨槸Spring瀹瑰櫒錛岃屼笖澶ч儴鍒嗘槸璇伙紝鑰屼笉鏄鍐欏茍鍔犮?br />
鍗曚緥闄烽槺鎴戝凡緇忓湪浠ュ墠甯栧瓙涓浜嗭紝鍙湁鍦ㄥ崟渚?鍐?鍚屾絳夋搷浣滀笅鎵嶅彲鑳芥閿侊紝鍥犱負浠g爜涓嶅彲鎺фэ紝浠婂ぉ浣犳敞鎰忔病榪欎箞鍋氾紝涓嶄唬琛ㄥ叾浠栨棤鐭ョ殑浜轟笉榪欎箞鍋氾紝鎵浠ワ紝榪欑singlton浼氳涓ヨ皚鐨勫伐鍏瘋涓烘槸楂樺嵄錛岃繖鏄紜殑銆?/span> |
ME:璋㈣阿 banq!
濡傛灉闇瑕佹秷闄よ繖孌甸珮鍗變唬鐮?闇瑕佸浣曢噸鏋?
鍥犱負鍙槸瀛樺湪璇繪搷浣?鎴戞槸鍚﹀彲浠ユ妸wac涓巆ontext瀹氫箟涓簊tatic(榪欐牱宸ュ叿涓嶄細鎶ラ敊)
璇烽棶榪欐牱鏀逛細涓嶄細鏈夐棶棰? |
banq:涓嶈兘鐢╯tatic錛岃繖鏍?a title="??" target="_blank">Spring瀹瑰櫒涓墍鏈夎祫婧愰兘涓嶈兘闅忕潃浣犵殑WEB欏圭洰娑堝け鑰屾秷澶便?br />
涓昏闂鍦ㄤ簬浣犵殑setServlet(ActionServlet actionServlet)榪欎釜鏂規硶錛岃繖鍏跺疄鏄竴涓垵濮嬪寲宸ヤ綔錛岃瘯楠屽湪BaseAction鐨勬瀯閫犳柟娉曚腑棣栧厛瀹炵幇錛岃繖鏍瘋〃紺烘湁鍓嶆湁鍚庯紝鍙兘涓嶄細鎶ラ珮鍗遍敊璇?br />
瀹炲湪涓嶈錛屽仛涓涓噿鍔犺澆鐨勬柟娉曪紝鍦ㄨ繖涓柟娉曚腑錛屾鏌ヤ竴涓媤ac鏄惁涓虹┖錛屽鏋滀負錛屽氨榪涜鍒濆鍖栵紝涓嶄負絀猴紝灝辯洿鎺ヨ繑鍥瀢ac鍊箋? |
鍘婚櫎setServlet鏂規硶錛屽湪getBean鍔犲叆錛屽涓嬶紝濡傛灉榪樹笉琛岋紝灝辨瘡嬈¤佽佸疄瀹炵殑鐢╓ebApplicationContextUtils鑾峰緱Spring瀹炰緥錛?br />
 protected Object getBean(String beanName) {
 if(wac==null) {
context = actionServlet.getServletContext();
wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
}

return wac.getBean(beanName);
}
|
|

]]>
主站蜘蛛池模板:
定安县|
临清市|
思南县|
永川市|
霞浦县|
吉木乃县|
昂仁县|
红桥区|
蕲春县|
屏东县|
商丘市|
昭苏县|
农安县|
五河县|
蓬安县|
田东县|
巴东县|
临朐县|
章丘市|
友谊县|
天祝|
会东县|
大渡口区|
汤阴县|
高唐县|
花莲市|
鹤山市|
阿坝|
柘荣县|
九龙城区|
金华市|
运城市|
龙海市|
乌鲁木齐市|
大英县|
达孜县|
肥乡县|
农安县|
新沂市|
金乡县|
城口县|