锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 絎竴涓猼ag瀹氫箟鐨勬槸spring鐨勯厤緗枃浠跺湴鍧鍒扮幆澧冨弬鏁?context parameter) 絎簩涓猼ag瀹氫箟涓涓猯istener涓?u>org.springframework.web.context.ContextLoaderListener,榪欓噷鐩稿綋浜巎2ee瀹瑰櫒緇欐垜浠彁渚涚殑main鍑芥暟鐨勫垏鍏ョ偣錛屽彲浠ヨ鎴戜滑鍋氫竴浜涚郴緇熷垵濮嬪寲鐨勫伐浣滐紝闇瑕佸疄鐜扮殑綾繪槸錛歫avax.servlet.ServletContextListener 絎笁涓猼ag鍒欏畾涔変簡struts2鐨勪竴涓猣ilter銆侳ilter鍒欐槸瀵規瘡嬈¤姹傦紙鍙互閫氳繃filter-mapping鎸囧畾錛夊仛榪囨護澶勭悊錛岃姹傞鍏堣榪噁ilter閾劇殑澶勭悊錛岀劧鍚庡啀鍒癏ttpServlet鐨刬nit鏂規硶銆傚搴旂殑綾繪槸錛歫avax.servlet.Filter銆備笂闈㈠厛閰嶇疆浜嗕竴涓猣ilter,瀵瑰簲鐨勭被鏄痮rg.apache.struts2.dispatcher.FilterDispatcher,鍙傛暟鍒欐槸struts鐨勯厤緗枃浠朵綅緗?/p>
絎洓涓弬鏁板畾涔変簡filter鎬庢牱琛屼負錛屾樉鐒跺畠瀵?do涓哄悗緙鐨勮姹傚簲鐢╯truts2榪欎釜鍚嶇О鐨刦ilter 鏌ョ湅ContextLoaderListener鍙煡錛屽畠姝eソ緇ф壙浜?u>javax.servlet.ServletContextListener錛岀敤浜庣洃鍚琷avax.servlet.ServletContextEvent浜嬩歡 姝ょ被implement浜哠ervletContextListener鐨勪袱涓柟娉曪細 鍒嗗埆鍋歝ontext鐨勫垵濮嬪寲鍜岄攢姣?/p>
鍙﹀鎻愪緵浜嗕竴涓猵rotected鏂規硶錛歱rotected ContextLoader createContextLoader() 鐢ㄤ簬鍒涘緩鐪熸鍋氫簨鎯呯殑浠g悊綾籆otextLoader 鍜屼竴涓猵ublic鏂規硶錛歱ublic ContextLoader getContextLoader()錛?/p>
鍙錛岃繖涓狶istener綾葷洿鎺ュ皢宸ヤ綔浠g悊緇欎簡ContextLoader綾諱簡 ____________________________________________________________________________________________________________________________ 鎴戜滑鎸夊浘绱㈤錛屼笅闈㈠啀鍒嗘瀽org.springframework.web.context.ContextLoader ContextLoader閲岄潰鏈変釜縐佹湁鎴愬憳錛歱rivate WebApplicationContext context 姝ゅ彉閲忔彁渚涗簡create鏂規硶錛?/p>
createWebApplicationContext(ServletContext servletContext, ApplicationContext parent)
鍥犱負Spring鎻愪緵浜嗗縐峎ebApplicationContext綾伙紝鎵浠ラ渶瑕佷竴涓柟娉曟潵鍐沖畾浣跨敤鍝釜WebApplicationContextContext綾?/p>
public static final String CONTEXT_CLASS_PARAM = "contextClass"; 鎵浠ュ鏋滃湪web.xml涓殑<context-param> </context-param>涓畾涔変簡鍙傛暟contextClass錛岄偅涔堢洿鎺ュ氨鍐沖畾浜嗙敤姝ontext綾?/p>
鍚﹀垯錛屽氨搴旂敤緙虹渷絳栫暐鏉ュ喅瀹氫嬌鐢ㄥ摢涓狢ontext綾匯?/p>
緙虹渷絳栫暐濡備笅錛?/p>
瀹為檯涓婏紝緙虹渷絳栫暐浠巓rg\springframework\web\context\ContextLoader.properties 鏂囦歡涓彇寰楀睘鎬rg.springframework.web.context.WebApplicationContext 鎴戜滑鐪嬬湅ContextLoader.properties鏂囦歡鐨勫唴瀹癸細 鏄劇劧錛岀己鐪佺殑Context綾誨氨鏄?XmlWebApplicationContext綾?/p>
錛侊紒錛佺湡绱晩錛孲pring... OK,鎬葷畻鐭ラ亾鐢ㄥ摢涓狢ontext綾諱簡錛岄偅涔堢幇鍦ㄥ埌浜哻reate榪欎釜Context瀹炰緥鐨勬椂鍊欎簡 榪欓噷寰堝鏄撶悊瑙o紝鍙笉榪囧畠鐨勫垱寤轟笉鏄洿鎺ew錛岃屾槸灝佽浜嗕竴灞傦紝璋冪敤BeanUtils.instantiateClass()宸ュ叿鏂規硶 鎺ヤ笅鏉ヨ瀹歐ebApplicationCcontext瀹炰緥鐨刾arent, servletContext, 鍏朵腑閰嶇疆鏂囦歡浣嶇疆(web.xml涓?鐨刢ontextConfigLocation鍙傛暟鎸囧畾鐨?/p>
鍊掓暟絎簩琛岃皟鐢ㄧ殑customizeContext()鏂規硶鐩墠Spring瀹炵幇浠g爜鏄┖鐨勶紝浼拌鐣欎綔浠ュ悗錛堢湅鏉ヤ竾浜嬭鐣欎綑鍦板晩^_^錛?/p>
鏈鍚庝竴浠朵簨灝辨槸璋冪敤WebApplicationContext鐨?font color="#ff0000" size="4">refresh()鏂規硶銆傦紙榪欎釜鏂規硶鏄釜stratup鏂規硶錛屽緢閲嶈銆備粬騫茬殑浜嬫儏鍚庨潰浼氱潃閲嶆秹鍙婏級 鏈鍚庡氨鏄湡姝e仛浜嬬殑initWebApplicationContext()鏂規硶錛?/p>
瀹冨叾瀹炲仛寰椾簨鎯呭緢綆鍗曪紝璋冪敤loadParentContext()鏂規硶鑾峰彇鐖禼ontext,璋冪敤createWebApplicationContext()鍒涘緩WebApplicationContext瀹炰緥 涓鍒囬兘浼間箮瀹屾垚浜嗭紝鑷沖皯鎴戜滑鏄庣櫧浜嗛厤緗枃浠舵槸濡備綍鍔犺澆榪涘幓鐨勶紝鑷充簬IoC瀹瑰櫒濡備綍甯綘娉ㄥ叆閰嶇疆鏂囦歡涓殑bean錛屼笅嬈″啀鎺㈢儲銆傜嚎绱㈡槸浠涔堝憿錛熶綘榪樿寰楀湪createWebApplication()鐨勬渶鍚庝竴姝ュ仛浠涔堜簡鍚楋紵refresh(), 瀵逛簡錛岃繖涓氨鏄綘浣滀負鑱屼笟"鍢垮"瑕佹帰绱㈢殑涓嬩竴涓嚎绱?/p> 棣栧厛澹版槑鍋朵篃涓嶆槸浠涔堥珮鎵嬶紝浠ヤ笅鎬葷粨閮芥槸鑷繁鐨勪綋浼氥備笉瀵逛箣澶勮鎮ㄥ鎸囨暀銆? PO錛?br>persistant object鎸佷箙瀵硅薄 BO錛?br>business object涓氬姟瀵硅薄 VO 錛?br>value object鍊煎璞?br>ViewObject琛ㄧ幇灞傚璞?br>涓昏瀵瑰簲鐣岄潰鏄劇ず鐨勬暟鎹璞°傚浜庝竴涓猈EB欏甸潰錛屾垨鑰匰WT銆丼WING鐨勪竴涓晫闈紝鐢ㄤ竴涓猇O瀵硅薄瀵瑰簲鏁翠釜鐣岄潰鐨勫箋? DTO 錛?br>Data Transfer Object鏁版嵁浼犺緭瀵硅薄 POJO 錛?br>plain ordinary java object 綆鍗昷ava瀵硅薄 DAO錛?br>data access object鏁版嵁璁塊棶瀵硅薄 web.xml瀹氫箟錛?br>.绔欏彴鐨勫悕縐板拰璇存槑 瑕佷簡瑙eb.xml鐨勮瀹氬鹼紝蹇呴』浜嗚В瀹冪殑schema,浠巜eb.xml涓煡閬撳畠鐨剆chema鏄敱Sum Microsystems鍏徃瀹氬埗鐨勶紝濡傛灉浣犳兂鏇翠負璇︾粏鐨勪簡瑙e畠錛?br>鍙互鍒?a >http://java.sun.com/xml/ns/j2ee/web-mapp_2_4.xsd緗戦〉錛岄偅閲屾湁鏇翠負璇︾粏鐨勪粙緇嶃傝繖閲屾垜浠嬬粛鎴戜滑騫沖父瑙佸緱鏈澶氱殑. <description>,<display-name>,<icon> <description>绔欏彴鎻忚堪</discription> <display-name>绔欏彴鍚嶇О</display-name> <icon> <large-icon>/璺緞/largeicon-jpg</large-icon> <distributable> <context-param> <context-param> 鍙堝Spring framework鍦ㄨ繖閲屽彲浠ヨ緗甤ontext鍙傛暟 <filter> 鍙堝Struts2鍙互鍦ㄨ繖閲岃filter <filter-mapping> ______________________________________ <servlet-name>Servlet鐨勫悕縐?lt;servlet-name> <servlet>
___________________________________________
<servlet-name>servlet鐨勫悕縐?lt;/servlet-name> <display-name>鏄劇ず鍚嶇О</display-name> 鑼冧緥錛?/p>
<servlet-mapping> <listener> 鍙堝Spring framework鍙互鍦ㄨ繖閲岃listener <session-cofing> <mime-mapping> <welcome-file-list> <error-page> <jsp-config> <taglib> <jsp-property-group> <display-name>Name</display-name> <url-pattern>URL</url-pattern> <el-ignored>true|false</el-ignored> <scripting-invalid>true|false</scripting-invalid> <page-encoding>encoding</page-encoding> <include-prelude>.jspf</include-prelude> <include-coda>.jspf</include-coda> <resource-ref> <rec-ref-name>璧勬簮鍚嶇О</rec-ref-name> <res-type>璧勬簮縐嶇被</res-type> <res-auth>Application|Container</res-auth> <res-sharing-scope>Shareable|Unshareable</res-sharing-scope> 榪欎簺閮芥槸浜涙瘮杈冨父鐢ㄧ殑,璇︾粏鍙互鐧誨綍: http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
1: <!-- spring鐨勯厤緗?-->
2: <context-param>
3: <param-name>contextConfigLocation</param-name>
4: <param-value>classpath:/SpringContext/applicationContext-web.xml</param-value>
5: </context-param>
7:
8: <listener>
9: <listener-class>org.springframework.web.context.ContextLoaderListener
10: </listener-class>
11: </listener>
12:
13: <filter>
14: <filter-name>struts2</filter-name>
15: <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
17: <init-param>
18: <param-name>config</param-name>
19: <param-value>struts-default.xml,struts-plugin.xml,struts/struts.xml</param-value>
20: </init-param>
21: </filter>
22:
23: <filter-mapping>
24: <filter-name>struts2</filter-name>
25: <url-pattern>*.do</url-pattern>
26: </filter-mapping>
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.context;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
/**
* Bootstrap listener to start up Spring's root {@link WebApplicationContext}.
* Simply delegates to {@link ContextLoader}.
*
* <p>This listener should be registered after
* {@link org.springframework.web.util.Log4jConfigListener}
* in <code>web.xml</code>, if the latter is used.
*
* @author Juergen Hoeller
* @since 17.02.2003
* @see ContextLoaderServlet
* @see org.springframework.web.util.Log4jConfigListener
*/
public class ContextLoaderListener implements ServletContextListener {
private ContextLoader contextLoader;
/**
* Initialize the root web application context.
*/
public void contextInitialized(ServletContextEvent event) {
this.contextLoader = createContextLoader();
this.contextLoader.initWebApplicationContext(event.getServletContext());
}
/**
* Create the ContextLoader to use. Can be overridden in subclasses.
* @return the new ContextLoader
*/
protected ContextLoader createContextLoader() {
return new ContextLoader();
}
/**
* Return the ContextLoader used by this listener.
* @return the current ContextLoader
*/
public ContextLoader getContextLoader() {
return this.contextLoader;
}
/**
* Close the root web application context.
*/
public void contextDestroyed(ServletContextEvent event) {
if (this.contextLoader != null) {
this.contextLoader.closeWebApplicationContext(event.getServletContext());
}
}
}
public void contextInitialized(ServletContextEvent event);
public void contextDestroyed(ServletContextEvent event);
protected Class determineContextClass(ServletContext servletContext) throws ApplicationContextException {
String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
if (contextClassName != null) {
try {
return ClassUtils.forName(contextClassName);
}
catch (ClassNotFoundException ex) {
throw new ApplicationContextException(
"Failed to load custom context class [" + contextClassName + "]", ex);
}
}
else {
contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());
try {
return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());
}
catch (ClassNotFoundException ex) {
throw new ApplicationContextException(
"Failed to load default context class [" + contextClassName + "]", ex);
}
}
}
private static final Properties defaultStrategies;
static {
// Load default strategy implementations from properties file.
// This is currently strictly internal and not meant to be customized
// by application developers.
try {
ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.class);
defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
}
catch (IOException ex) {
throw new IllegalStateException("Could not load 'ContextLoader.properties': " + ex.getMessage());
}
}
# Default WebApplicationContext implementation class for ContextLoader.
# Used as fallback when no explicit context implementation has been specified as context-param.
# Not meant to be customized by application developers.
org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext
protected WebApplicationContext createWebApplicationContext(
ServletContext servletContext, ApplicationContext parent) throws BeansException {
Class contextClass = determineContextClass(servletContext);
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Custom context class [" + contextClass.getName() +
"] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]");
}
ConfigurableWebApplicationContext wac =
(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
wac.setParent(parent);
wac.setServletContext(servletContext);
wac.setConfigLocation(servletContext.getInitParameter(CONFIG_LOCATION_PARAM));
customizeContext(servletContext, wac);
wac.refresh();
return wac;
}
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/SpringContext/applicationContext-web.xml
</param-value>
</context-param>
public WebApplicationContext initWebApplicationContext(ServletContext servletContext)
throws IllegalStateException, BeansException {
if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
throw new IllegalStateException(
"Cannot initialize context because there is already a root application context present - " +
"check whether you have multiple ContextLoader* definitions in your web.xml!");
}
servletContext.log("Initializing Spring root WebApplicationContext");
if (logger.isInfoEnabled()) {
logger.info("Root WebApplicationContext: initialization started");
}
long startTime = System.currentTimeMillis();
try {
// Determine parent for root web application context, if any.
ApplicationContext parent = loadParentContext(servletContext);
// Store context in local instance variable, to guarantee that
// it is available on ServletContext shutdown.
this.context = createWebApplicationContext(servletContext, parent);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
currentContextPerThread.put(Thread.currentThread().getContextClassLoader(), this.context);
if (logger.isDebugEnabled()) {
logger.debug("Published root WebApplicationContext as ServletContext attribute with name [" +
WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");
}
if (logger.isInfoEnabled()) {
long elapsedTime = System.currentTimeMillis() - startTime;
logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
}
return this.context;
}
catch (RuntimeException ex) {
logger.error("Context initialization failed", ex);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
throw ex;
}
catch (Error err) {
logger.error("Context initialization failed", err);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);
throw err;
}
}
鏈褰㈣薄鐨勭悊瑙e氨鏄竴涓狿O灝辨槸鏁版嵁搴撲腑鐨勪竴鏉¤褰曘?br>濂藉鏄彲浠ユ妸涓鏉¤褰曚綔涓轟竴涓璞″鐞嗭紝鍙互鏂逛究鐨勮漿涓哄叾瀹冨璞°?
涓昏浣滅敤鏄妸涓氬姟閫昏緫灝佽涓轟竴涓璞°傝繖涓璞″彲浠ュ寘鎷竴涓垨澶氫釜鍏跺畠鐨勫璞°?br>姣斿涓涓畝鍘嗭紝鏈夋暀鑲茬粡鍘嗐佸伐浣滅粡鍘嗐佺ぞ浼氬叧緋葷瓑絳夈?br>鎴戜滑鍙互鎶婃暀鑲茬粡鍘嗗搴斾竴涓狿O錛屽伐浣滅粡鍘嗗搴斾竴涓狿O錛岀ぞ浼氬叧緋誨搴斾竴涓狿O銆?br>寤虹珛涓涓搴旂畝鍘嗙殑BO瀵硅薄澶勭悊綆鍘嗭紝姣忎釜BO鍖呭惈榪欎簺PO銆?br>榪欐牱澶勭悊涓氬姟閫昏緫鏃訛紝鎴戜滑灝卞彲浠ラ拡瀵笲O鍘誨鐞嗐?
涓昏鐢ㄤ簬榪滅▼璋冪敤絳夐渶瑕佸ぇ閲忎紶杈撳璞$殑鍦版柟銆?br>姣斿鎴戜滑涓寮犺〃鏈?00涓瓧孌碉紝閭d箞瀵瑰簲鐨凱O灝辨湁100涓睘鎬с?br>浣嗘槸鎴戜滑鐣岄潰涓婂彧瑕佹樉紺?0涓瓧孌碉紝
瀹㈡埛绔敤WEB service鏉ヨ幏鍙栨暟鎹紝娌℃湁蹇呰鎶婃暣涓狿O瀵硅薄浼犻掑埌瀹㈡埛绔紝
榪欐椂鎴戜滑灝卞彲浠ョ敤鍙湁榪?0涓睘鎬х殑DTO鏉ヤ紶閫掔粨鏋滃埌瀹㈡埛绔紝榪欐牱涔熶笉浼氭毚闇叉湇鍔$琛ㄧ粨鏋?鍒拌揪瀹㈡埛绔互鍚庯紝濡傛灉鐢ㄨ繖涓璞℃潵瀵瑰簲鐣岄潰鏄劇ず錛岄偅姝ゆ椂瀹冪殑韜喚灝辮漿涓篤O
涓漢鎰熻POJO鏄渶甯歌鏈澶氬彉鐨勫璞★紝鏄竴涓腑闂村璞★紝涔熸槸鎴戜滑鏈甯告墦浜ら亾鐨勫璞°?br>涓涓狿OJO鎸佷箙鍖栦互鍚庡氨鏄疨O
鐩存帴鐢ㄥ畠浼犻掋佷紶閫掕繃紼嬩腑灝辨槸DTO
鐩存帴鐢ㄦ潵瀵瑰簲琛ㄧず灞傚氨鏄疺O
榪欎釜澶у鏈鐔熸倝錛屽拰涓婇潰鍑犱釜O鍖哄埆鏈澶э紝鍩烘湰娌℃湁浜掔浉杞寲鐨勫彲鑳芥у拰蹇呰.
涓昏鐢ㄦ潵灝佽瀵規暟鎹簱鐨勮闂傞氳繃瀹冨彲浠ユ妸POJO鎸佷箙鍖栦負PO錛岀敤PO緇勮鍑烘潵VO銆丏TO
鎬葷粨涓嬫垜璁や負涓涓璞$┒绔熸槸浠涔圤瑕佺湅鍏蜂綋鐜錛屽湪涓嶅悓鐨勫眰銆佷笉鍚岀殑搴旂敤鍦哄悎錛屽璞$殑韜喚涔熶笉涓鏍鳳紝鑰屼笖瀵硅薄韜喚鐨勮漿鍖栦篃鏄緢鑷劧鐨勩傚氨鍍忎綘瀵硅佸﹩鏉ヨ灝辨槸鑰佸叕錛屽鐖舵瘝鏉ヨ灝辨槸瀛愬コ銆傝璁¤繖浜涙蹇電殑鍒濊》涓嶆槸涓轟簡鍞漢鑰屾槸涓轟簡鏇村ソ鐨勭悊瑙e拰澶勭悊鍚勭閫昏緫錛岃澶у鑳芥洿濂界殑鍘葷敤闈㈠悜瀵硅薄鐨勬柟寮忓鐞嗛棶棰?
澶у鍗冧竾涓嶈闄峰叆榪囧害璁捐錛屽ぇ鍙笉蹇呬負浜嗚璁¤岃璁′竴瀹氳鍦ㄤ唬鐮佷腑鍖哄垎鍚勪釜瀵硅薄銆備竴鍙ヨ瘽鎶鏈槸涓哄簲鐢ㄦ湇鍔$殑銆?br>嬈㈣繋鎸囨銆?
鐢諱簡涓浘錛屾劅瑙夋病鏈夊畬鍏ㄨ〃杈懼嚭鑷繁鐨勬剰鎬濄傘傘傘傘傝皝甯繖瀹屽杽涓嬶紝鏈濂借兘浣撶幇鍚勪釜O鍦∕VC涓殑浣嶇疆
.閽堝鐜鍙傛暟(Context)鍋氬垵濮嬪寲宸ヤ綔
.Servlet鐨勫悕縐板拰鏄犲皠
.Session鐨勮瀹?br>.Tag library鐨勫鏄?br>.JSP緗戦〉璁懼畾
.Mime Type澶勭悊
.閿欒澶勭悊
.鍒╃敤JDNI鍙栧緱绔欏彴璧勬簮 1: <?xml version="1.0" encoding="ISO-8859-1"?>
2:
3: <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
4: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5: xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
6: version="2.4">
7: <web-app>
榪欐槸涓鑸湪鍐橷ML鏃舵墍鍋氱殑澹版槑,瀹氫箟浜哫ML鐨勭増鏈紝緙栫爜鏍煎紡,榪樻湁閲嶈鐨勬寚鏄巗chema鐨勬潵婧?涓?a >http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd.
____________________________________________
瀵圭珯鍙板仛鍑烘弿榪?
瀹氫箟绔欏彴鐨勫悕縐?
icon鍏冪礌鍖呭惈small-icon鍜宭arge-icon涓や釜瀛愬厓绱?鐢ㄦ潵鎸囧畾web绔欏彴涓皬鍥炬爣鍜屽ぇ鍥炬爣鐨勮礬寰?
<small-icon>/璺緞/smallicon.gif</small-icon>
small-icon鍏冪礌搴旀寚鍚憌eb绔欏彴涓煇涓皬鍥炬爣鐨勮礬寰?澶у皬涓?6 X 16 pixel,浣嗘槸鍥捐薄鏂囦歡蹇呴』涓篏IF鎴朖PEG鏍煎紡,鎵╁睍鍚嶅繀欏諱負:.gif鎴?jpg.
large-icon鍏冪礌搴旀寚鍚憌eb绔欏彴涓煇涓ぇ鍥捐〃璺緞,澶у皬涓?2 X 32 pixel,浣嗘槸鍥捐薄鏂囦歡蹇呴』涓篏IF鎴朖PEG鐨勬牸寮?鎵╁睍鍚嶅繀欏諱負; gif
鎴杍pg.
鑼冧緥: 1: <display-name>Develop Example</display-name>
2: <description>JSP 2.0 Tech Book's Examples</description>
3: <icon>
4: <small-icon>/images/small.gif</small-icon>
5: <large-icon>/images/large.gir</large-icon>
6: </icon>
7:
8: <distributable>
______________________________________
distributable 鍏冪礌涓虹┖鏍囩,瀹冪殑瀛樺湪涓庡惁鍙互鎸囧畾绔欏彴鏄惁鍙垎甯冨紡澶勭悊.濡傛灉web.xml涓嚭鐜拌繖涓厓绱?鍒欎唬琛ㄧ珯鍙板湪寮鍙戞椂宸茬粡
琚璁′負鑳藉湪澶氫釜JSP Container 涔嬮棿鍒嗘暎鎵ц.
鑼冧緥: 1: <distributable/>
___________________________________
context-param 鍏冪礌鐢ㄦ潵璁懼畾web绔欑偣鐨?u>鐜鍙傛暟(context),瀹冨寘鍚袱涓瓙鍏冪礌:
param-name鍜宲aram-value.
<param-name>鍙傛暟鍚嶇О</param-name>
璁懼畾Context鍚嶇О
<param-value>鍊?lt;/param-value>
璁懼畾Context鍚嶇О鐨勫?br></context-param>
鑼冧緥: 1: <context-param>
2: <param-name>param_name</param-name>
3: <param-value>param_value</param-value>
4: </context-param>
姝ゆ墍璁懼畾鐨勫弬鏁?鍦↗SP緗戦〉涓彲浠ヤ嬌鐢ㄤ笅鍒楁柟娉曟潵鍙栧緱: 1: ${initParam.param_name}
鑻ュ湪Servlet鍙互浣跨敤涓嬪垪鏂規硶鏉ヨ幏寰? 1: String param_name=getServletContext().getInitParamter("param_name");
1: <!-- spring鐨勯厤緗?-->
2: <context-param>
3: <param-name>contextConfigLocation</param-name>
4: <param-value>classpath:/SpringContext/applicationContext-web.xml
5: </param-value>
6: </context-param>
_________________________________
filter鍏冪礌鐢ㄦ潵澹版槑filter鐨勭浉鍏寵瀹?filter鍏冪礌闄や簡涓嬮潰浠嬬粛鐨勭殑瀛愬厓绱犱箣澶?榪樺寘鎷?lt;servlet>浠嬬粛榪囩殑<icon>,<display-name>
,<description>,<init-param>,鍏剁敤閫斾竴鏍?
<filter-name>Filter鐨勫悕縐?lt;/filter-name>
瀹氫箟Filter鐨勫悕縐?
<filter-class>Filter鐨勭被鍚嶇О</filter-class>
瀹氫箟Filter鐨勭被鍚嶇О.渚嬪:com.foo.hello
鑼冧緥: 1: <filter>
2: <filter-name>setCharacterEncoding</filter-name>
3: <filter-class>coreservlet.javaworld.CH11.SetCharacterEncodingFilter</filter-class>
4: <init-param>
5: <param-name>encoding</param-name>
6: <param-value>GB2312</param-value>
7: </init-param>
8: </filter>
9:
10: <filter-mapping>
1: <filter>
2: <filter-name>struts2</filter-name>
3: <filter-class>org.apache.struts2.dispatcher.FilterDispatcher
4: </filter-class>
5: <init-param>
6: <param-name>config</param-name>
7: <param-value>struts-default.xml,struts-plugin.xml,struts/struts.xml</param-value>
8: </init-param>
9: </filter>
10:
11: <filter-mapping>
12: <filter-name>struts2</filter-name>
13: <url-pattern>*.do</url-pattern>
14: </filter-mapping>
filter-mapping 鍏冪礌鐨勪袱涓富瑕佸瓙鍏冪礌filter-name鍜寀rl-pattern.鐢ㄦ潵瀹氫箟Filter鎵瀵瑰簲鐨刄RL.
<filter-name>Filter鐨勫悕縐?lt;/filter-name>
瀹氫箟Filter鐨勫悕縐?
<url-pattern>URL</url-pattern>
Filter鎵瀵瑰簲鐨凴UL.渚嬪:<url-pattern>/Filter/Hello</url-pattern>
瀹氫箟servlet鐨勫悕縐?
<dispatcher>REQUEST|INCLUDE|FORWARD|ERROR</disaptcher>
璁懼畾Filter瀵瑰簲鐨勮姹傛柟寮?鏈塕QUEST,INCLUDE,FORWAR,ERROR鍥涚,榛樿涓篟EQUEST.
</filter-mapping>
鑼冧緥: 1: <filter-mapping>
2: <filter-name>GZIPEncoding</filter-name>
3: <url-pattern>/*</url-pattern>
4: </filter-mapping>
<servlet-class>servlet瀵瑰簲鐨刢lass鍚?lt;/servlet-class>
1: <servlet>
2: <servlet-name>org.apache.jsp.index_jsp</servlet-name>
3: <servlet-class>org.apache.jsp.index_jsp</servlet-class>
4: </servlet>
_____________________________________________
servlet-mapping鍏冪礌鍖呭惈涓や釜瀛愬厓绱爏ervlet-name鍜寀rl-pattern.鐢ㄦ潵瀹氫箟servlet鎵瀵瑰簲URL.
<servlet-name>Servlet鐨勫悕縐?lt;/servlet-name>
瀹氫箟Servlet鐨勫悕縐?
<url-pattern>Servlet URL</url-pattern>
瀹氫箟Servlet鎵瀵瑰簲鐨凴UL.渚嬪:<url-pattern>/Servlet/Hello</url-pattern>
</servlet-mapping>
鑼冧緥: 1: <servlet-mapping>
2: <servlet-name>LoginChecker</servlet-name>
3: <url-pattern>/LoginChecker</url-pattern>
4: </servlet-mapping>
___________________________________________
<listener>
listener鍏冪礌鐢ㄦ潵瀹氫箟Listener鎺ュ彛,瀹冪殑涓昏瀛愬厓绱犱負<listener-class>
<listen-class>Listener鐨勭被鍚嶇О</listener-class>
瀹氫箟Listener鐨勭被鍚嶇О.渚嬪: com.foo.hello
<listener>
鑼冧緥: 1: <listener>
2: <listener-class>coreservlet.javaworld.CH11.ContenxtListener</listener-class>
3: </listener>
1: <listener>
2: <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
3: </listener>
__________________________________
<session-config>
session-config鍖呭惈涓涓瓙鍏冪礌session-timeout.瀹氫箟web绔欏彴涓殑session鍙傛暟.
<session-timeout>鍒嗛挓</session-timeout>
瀹氫箟榪欎釜web绔欏彴鎵鏈塻ession鐨勬湁鏁堟湡闄?鍗曚綅涓哄垎閽?
</session-config>
鑼冧緥: 1: <session-config>
2: <session-timeout>20</session-timeout>
3: </session-config>
___________________________________________________
<mima-mapping>
mime-mapping鍖呭惈涓や釜瀛愬厓绱爀xtension鍜宮ime-type.瀹氫箟鏌愪竴涓墿灞曞悕鍜屾煇涓MIME Type鍋氬鏄?
<extension>鎵╁睍鍚嶅悕縐?lt;/extension>
鎵╁睍鍚嶇О
<mime-type>MIME鏍煎紡</mime-type>
MIME鏍煎紡.
</mime-mapping>
鑼冧緥: 1: <mime-mapping>
2: <extension>doc</extension>
3: <mime-type>application/vnd.ms-word</mime-type>
4: </mime-mapping>
5: <mime-mapping>
6: <extension>xls</extension>
7: <mime-type>application/vnd.ms-excel</mime-type>
8: </mime-mapping>
9: <mime-mapping>
10: <extension>ppt</extesnion>
11: <mime-type>application/vnd.ms-powerpoint</mime-type>
12: </mime-mapping>
_____________________________________________
<welcome-file-list>
welcome-file-list鍖呭惈涓涓瓙鍏冪礌welcome-file.鐢ㄦ潵瀹氫箟棣栭〉鍒楀崟.
<welcome-file>鐢ㄦ潵鎸囧畾棣栭〉鏂囦歡鍚嶇О</welcome-flie>
welcome-file鐢ㄦ潵鎸囧畾棣栭〉鏂囦歡鍚嶇О.鎴戜滑鍙互鐢?lt;welcome-file>鎸囧畾鍑犱釜棣栭〉,鑰屾湇鍔″櫒浼氫緷鐓ц瀹氱殑欏哄簭鏉ユ壘棣栭〉.
鑼冧緥: 1: <welcome-file-list>
2: <welcome-file>index.jsp</welcome-file>
3: <welcome-file>index.htm</welcome-file>
4: </welcome-file-list>
_________________________
<error-page>
error-page鍏冪礌鍖呭惈涓変釜瀛愬厓绱爀rror-code,exception-type鍜宭ocation.灝嗛敊璇唬鐮?Error Code)鎴栧紓甯?Exception)鐨勭綾誨搴?br>鍒皐eb绔欏彴璧勬簮璺緞.
<error-code>閿欒浠g爜</error-code>
HTTP Error code,渚嬪: 404
<exception-type>Exception</exception-type>
涓涓畬鏁村悕縐扮殑Java寮傚父綾誨瀷
<location>/璺緞</location>
鍦╳eb绔欏彴鍐呯殑鐩稿叧璧勬簮璺緞
</error-page>
鑼冧緥: 1: <error-page>
2: <error-code>404</error-code>
3: <location>/error404.jsp</location>
4: </error-page>
5: <error-page>
6: <exception-type>java.lang.Exception</exception-type>
7: <location>/except.jsp</location>
8: </error-page>
_______________________________________________
<jsp-config>
jsp-config鍏冪礌涓昏鐢ㄦ潵璁懼畾JSP鐨勭浉鍏抽厤緗?<jsp:config>鍖呮嫭<taglib>鍜?lt;jsp-property-group>涓や釜瀛愬厓绱?鍏朵腑<taglib>鍏冪礌
鍦↗SP 1.2鏃跺氨宸茬粡瀛樺湪浜?鑰?lt;jsp-property-group>鏄疛SP 2.0鏂板鐨勫厓绱?
taglib鍏冪礌鍖呭惈涓や釜瀛愬厓绱爐aglib-uri鍜宼aglib-location.鐢ㄦ潵璁懼畾JSP緗戦〉鐢ㄥ埌鐨凾ag Library璺緞.
<taglib-uri>URI</taglib-uri>
taglib-uri瀹氫箟TLD鏂囦歡鐨刄RI,JSP緗戦〉鐨則aglib鎸囦護鍙互緇忕敱榪欎釜URI瀛樺彇鍒癟LD鏂囦歡.
<taglib-location>/WEB-INF/lib/xxx.tld</taglib-laction>
TLD鏂囦歡瀵瑰簲Web绔欏彴鐨勫瓨鏀句綅緗?
</taglib>
jsp-property-group鍏冪礌鍖呭惈8涓厓绱?鍒嗗埆涓?
<description>Description</descrition>
姝よ瀹氱殑璇存槑
姝よ瀹氱殑鍚嶇О
璁懼畾鍊兼墍褰卞搷鐨勮寖鍥?濡?/CH2 鎴栬?*.jsp
鑻ヤ負true,琛ㄧず涓嶆敮鎸丒L璇硶.
鑻ヤ負true琛ㄧず涓嶆敮鎸?lt;%scription%>璇硶.
璁懼畾JSP緗戦〉鐨勭紪鐮?
璁劇疆JSP緗戦〉鐨勬姮澶?鎵╁睍鍚嶄負.jspf
璁劇疆JSP緗戦〉鐨勭粨灝?鎵╁睍鍚嶄負.jspf
</jsp-property-group>
</jsp-config>
鑼冧緥: 1: <jsp-config>
2: <taglib>
3: <taglib-uri>Taglib</taglib-uri>
4: <taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>
5: </taglib>
6: <jsp-property-group>
7: <description>
8: Special property group for JSP Configuration JSP example.
9: </description>
10: <display-name>JSPConfiguration</display-name>
11: <uri-pattern>/*</uri-pattern>
12: <el-ignored>true</el-ignored>
13: <page-encoding>GB2312</page-encoding>
14: <scripting-inivalid>true</scripting-inivalid>
15: ............
16: </jsp-property-group>
17: </jsp-config>
________________________________________________
<resource-ref>
resource-ref鍏冪礌鍖呮嫭浜斾釜瀛愬厓绱燿escription,res-ref-name,res-type,res-auth,res-sharing-scope.鍒╃敤JNDI鍙栧緱绔欑偣鍙?br>鍒╃敤璧勬簮.
<description>璇存槑</description>
璧勬簮璇存槑
璧勬簮鍚嶇О
璧勬簮縐嶇被
璧勬簮鐢盇pplication鎴朇ontainer鏉ヨ鍙?
璧勬簮鏄惁鍙互鍏變韓.榛樿鍊間負 Shareable
鑼冧緥: 1: <resource-ref>
2: <description>JNDI JDBC DataSource of JSPBook</description>
3: <res-ref-name>jdbc/sample_db</res-ref-name>
4: <res-type>javax.sql.DataSoruce</res-type>
5: <res-auth>Container</res-auth>
6: </resource-ref>
鍙渶瑕佹寚瀹氶渶瑕佺敓鎴愮殑鐩綍錛屽氨鍙互鎵歸噺灝?BO.java杞崲涓?VO.as
浠g爜濡備笅錛?/p>
1: /**
2: *
3: */
4: package com.suprasoft.utils.flex;
5:
6: /**
7: * @浣滆?Charles <chio.yang@gmail.com> Suprasoft Inc.,
8: *
9: * 2008-12-25
10: */
11:
12: import java.io.BufferedWriter;
13: import java.io.File;
14: import java.io.FileWriter;
15: import java.io.IOException;
16: import java.lang.reflect.Field;
17:
18: import org.apache.commons.lang.StringUtils;
19:
20: public class POJO2VO {
21: public POJO2VO() {
22: }
23:
24: public static String getClassType(Class c) {
25: String typeName = c.getSimpleName();
26: // System.out.println("typename " + typeName);
27: // 鏁板煎瀷鐨勯兘杞垚Number
28: if (typeName.equals("BigDecimal") || typeName.equals("Decimal")
29: || typeName.equals("Double") || typeName.equals("int")
30: || typeName.equals("Integer") || typeName.equals("Long")
31: || typeName.equals("long")) {
32: return "Number";
33: } else if (typeName.equals("Boolean")) {
34: return "boolean";
35: } else if (typeName.equals("Set")) {
36: return "Array";
37: } else {
38: if (isBasicType(typeName)) {
39: return typeName;// 鍏跺畠綾誨瀷鐨勮緗負鏈煡綾誨瀷
40: } else {
41: return typeName + "VO";// 鑷畾涔夌被鍨嬬殑錛屽姞涓奦O緇撳熬
42: }
43: }
44:
45: }
46:
47: // 鏄惁鍩烘湰鐨勬暟鎹被鍨?/span>
48: public static boolean isBasicType(String type) {
49: return type.equals("String") || type.equals("BigDecimal")
50: || type.equals("Decimal") || type.equals("Double")
51: || type.equals("int") || type.equals("Integer")
52: || type.equals("Boolean") || type.equals("Set")
53: || type.equals("Long") || type.equals("long")
54: || type.equals("Date");
55: }
56:
57: public static String repeat(String c, int count) {
58: String temp = "";
59: for (int i = 0; i < count; i++) {
60: temp += c;
61: }
62:
63: return temp;
64: }
65:
66: public static void makeDirByPackageName(String rootFolder, String packageName) {
67:
68: File folder = new File(rootFolder + "\\" + packageName.replace(".", "\\"));
69: if(!folder.exists()) {
70: folder.mkdirs();
71: }
72: }
73:
74: public static void generateAsFiles(String pojoQualifiedName ){
75:
76: }
77:
78: /**
79: * 鐢熸垚as鏂囦歡
80: *
81: * @param pojoQualifiedName
82: * @param voPackageName
83: * @param folders
84: * @throws ClassNotFoundException
85: * @throws IOException
86: */
87: public static void generateAsFile(String pojoQualifiedName, String voPackageRootFolder, String voPackageName) throws ClassNotFoundException, IOException {
88: //pojoName蹇呴』甯﹀寘鍚嶇殑Qualified Name
89: Class c = Class.forName(pojoQualifiedName);
90: Field[] fields = c.getDeclaredFields();
91:
92: POJO2VO.makeDirByPackageName(voPackageRootFolder, voPackageName);
93: // as鐨剉o瀵硅薄鍚嶇О緇撳熬鍔犱笂VO鏍囧織
94: File f = new File(voPackageRootFolder + "\\"
95: + voPackageName.replace(".", "\\") + "\\"
96: + c.getSimpleName().replace("BO", "VO") + ".as");
97:
98: BufferedWriter bw = new BufferedWriter(new FileWriter(f));
99: // 鍖呭悕錛屾病鏈夎緗寘鍚嶅氨鍙栧拰java pojo涓鏍風殑鍖呭悕
100: if (StringUtils.isEmpty(voPackageName)) {
101: bw.write("package " + c.getPackage().getName() + "\n{\n");
102: } else {
103: bw.write("package " + voPackageName + "\n{\n");
104: }
105:
106: // 鍐欑被
107: bw.write(repeat(" ", 4) + "public class " + c.getSimpleName().replace("BO", "VO") + "\n");
108: bw.write(repeat(" ", 4) + "{\n");
109:
110: // 鍐欏睘鎬?/pre>111: for (int i = 0; i < fields.length; i++) {
112: Class fieldType = fields[i].getType();
113: String typeName = getClassType(fieldType);
114: bw.write(repeat(" ", 8) + "private var _" + fields[i].getName()115: + ":" + typeName + ";\n");116: }
117:
118: bw.write("\n\n\n");119: // 鍐欑┖鐨勬瀯閫犲嚱鏁?/pre>120: bw.write(repeat(" ", 8) + "public function " + c.getSimpleName().replace("BO", "VO")121: + "(){}\n\n");122:
123: // 鍐?setter/getter 鏂規硶
124: for (int i = 0; i < fields.length; i++) {
125: Class fieldType = fields[i].getType();
126: String typeName = getClassType(fieldType);
127: // setter
128: bw.write(repeat(" ", 8) + "public function set "129: + fields[i].getName() + "(value:" + typeName + "):void{\n");130: bw.write(repeat(" ", 12) + "this._" + fields[i].getName()131: + " = value;\n");132: bw.write(repeat(" ", 8) + "}\n\n");133: // getter
134: bw.write(repeat(" ", 8) + "public function get "135: + fields[i].getName() + "():" + typeName + "{\n");136: bw.write(repeat(" ", 12) + "return this._" + fields[i].getName()137: + ";\n");138: bw.write(repeat(" ", 8) + "}\n\n\n");139:
140: }
141: bw.write(repeat(" ", 4) + "}\n");142: bw.write("}");143: bw.close();
144: }
145:
146: public static void generateAsFileBatch(String pojoPackageRootFolder, String pojoPackageName, String voPackageRootFolder, String voPackageName) throws ClassNotFoundException, IOException {
147: String packageFolder = pojoPackageRootFolder + "\\" + pojoPackageName.replace(".", "\\");148: File dir = new File(packageFolder);
149: File[] files = dir.listFiles();
150: for(File file : files){
151: if(file.isDirectory()) continue;
152:
153: if(file.getName().endsWith("BO.java")){154: String pojoName = pojoPackageName + "." + file.getName().replace(".java", "");155: POJO2VO.generateAsFile(pojoName, voPackageRootFolder, voPackageName);
156: }
157: }
158: }
159:
160:
161: /*
162: * 嫻嬭瘯
163: */
164: public static void main(String[] args) throws ClassNotFoundException, IOException {
165:
166: // String[] pojos = { "com.bankcomm.icms.domain.migrate.RawCollateralBasicBO" };167: // for (int i = 0; i < pojos.length; i++) {
168: // POJO2VO.generateAsFile(pojos[i], "C:", "com.bankcomm.icms.domain");169: // }
170:
171: POJO2VO.generateAsFileBatch("D:\\ICMS\\eclipse\\workspace\\Utils\\src\\",172: "com.bankcomm.icms.domain.migrate",173: "C:\\Documents and Settings\\Administrator\\My Documents\\Flex Builder 3\\Temp\\src",174: "com.bankcomm.icms.domain");
175: }
176: }