??xml version="1.0" encoding="utf-8" standalone="yes"?>伊人成综合网伊人222,97久久中文字幕,精品999久久久http://www.aygfsteel.com/charles/category/36706.html以JEEZ攻,以Flex为点~Q以Eclipse RCPZ?/description>zh-cnMon, 16 Feb 2009 20:48:31 GMTMon, 16 Feb 2009 20:48:31 GMT60在Spring基础上实现自q异常处理框架 http://www.aygfsteel.com/charles/archive/2009/02/12/254469.htmlsuprasoft Inc,.suprasoft Inc,.Thu, 12 Feb 2009 14:58:00 GMThttp://www.aygfsteel.com/charles/archive/2009/02/12/254469.htmlhttp://www.aygfsteel.com/charles/comments/254469.htmlhttp://www.aygfsteel.com/charles/archive/2009/02/12/254469.html#Feedback0http://www.aygfsteel.com/charles/comments/commentRss/254469.htmlhttp://www.aygfsteel.com/charles/services/trackbacks/254469.html阅读全文

suprasoft Inc,. 2009-02-12 22:58 发表评论
]]>
读Spring源代码之按图索骥Q一QContext创徏与配|文件加?/title><link>http://www.aygfsteel.com/charles/archive/2008/12/26/248497.html</link><dc:creator>suprasoft Inc,.</dc:creator><author>suprasoft Inc,.</author><pubDate>Fri, 26 Dec 2008 08:53:00 GMT</pubDate><guid>http://www.aygfsteel.com/charles/archive/2008/12/26/248497.html</guid><wfw:comment>http://www.aygfsteel.com/charles/comments/248497.html</wfw:comment><comments>http://www.aygfsteel.com/charles/archive/2008/12/26/248497.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/charles/comments/commentRss/248497.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/charles/services/trackbacks/248497.html</trackback:ping><description><![CDATA[<p>Spring ?Struts在web.xml中增加的配置Q?/p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="lnum"> 1:</span> <span id="wmqeeuq" class="rem"><!-- spring的配|?--></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 2:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">context-param</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 3:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">param-name</span><span id="wmqeeuq" class="kwrd">></span>contextConfigLocation<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">param-name</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 4:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">param-value</span><span id="wmqeeuq" class="kwrd">></span>classpath:/SpringContext/applicationContext-web.xml<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">param-value</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 5:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">context-param</span><span id="wmqeeuq" class="kwrd">></span> </pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 7:</span>  </pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 8:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">listener</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 9:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">listener-class</span><span id="wmqeeuq" class="kwrd">></span>org.springframework.web.context.ContextLoaderListener</pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 10:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">listener-class</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 11:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">listener</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 12:</span>  </pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 13:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">filter</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 14:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">filter-name</span><span id="wmqeeuq" class="kwrd">></span>struts2<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">filter-name</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 15:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">filter-class</span><span id="wmqeeuq" class="kwrd">></span>org.apache.struts2.dispatcher.FilterDispatcher<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">filter-class</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 17:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">init-param</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 18:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">param-name</span><span id="wmqeeuq" class="kwrd">></span>config<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">param-name</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 19:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">param-value</span><span id="wmqeeuq" class="kwrd">></span>struts-default.xml,struts-plugin.xml,struts/struts.xml<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">param-value</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 20:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">init-param</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 21:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">filter</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 22:</span>  </pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 23:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">filter-mapping</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 24:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">filter-name</span><span id="wmqeeuq" class="kwrd">></span>struts2<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">filter-name</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alt"><span id="wmqeeuq" class="lnum"> 25:</span> <span id="wmqeeuq" class="kwrd"><</span><span id="wmqeeuq" class="html">url-pattern</span><span id="wmqeeuq" class="kwrd">></span>*.do<span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">url-pattern</span><span id="wmqeeuq" class="kwrd">></span></pre><pre class="alteven"><span id="wmqeeuq" class="lnum"> 26:</span> <span id="wmqeeuq" class="kwrd"></</span><span id="wmqeeuq" class="html">filter-mapping</span><span id="wmqeeuq" class="kwrd">></span></pre></div></div> <p> </p> <p>W一个tag定义的是spring的配|文件地址到环境参?context parameter)</p> <p>W二个tag定义一个listener?u>org.springframework.web.context.ContextLoaderListener</u>,q里相当于j2ee容器l我们提供的main函数的切入点Q可以让我们做一些系l初始化的工作,需要实现的cLQjavax.servlet.ServletContextListener</p> <p>W三个tag则定义了struts2的一个filter。Filter则是Ҏơ请求(可以通过filter-mapping指定Q做qo处理Q请求首先请qfilter铄处理Q然后再到HttpServlet的initҎ。对应的cLQjavax.servlet.Filter。上面先配置了一个filter,对应的类是org.apache.struts2.dispatcher.FilterDispatcher,参数则是struts的配|文件位|?/p> <p>W四个参数定义了filter怎样行ؓQ显然它?do为后~的请求应用struts2q个名称的filter</p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt">q里需要首先搞清楚servlet规范中什么是listener?</pre><pre class="alteven"> </pre><pre class="alt">详细请参?<a >Servlet Listener和Filter</a></pre></div></div> <p> </p> <p>查看ContextLoaderListener可知Q它正好l承?u>javax.servlet.ServletContextListener</u>Q用于监听javax.servlet.ServletContextEvent事g</p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="rem">/*</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * Copyright 2002-2007 the original author or authors.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> *</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * Licensed under the Apache License, Version 2.0 (the "License");</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * you may not use this file except in compliance with the License.</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * You may obtain a copy of the License at</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> *</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * http://www.apache.org/licenses/LICENSE-2.0</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> *</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * Unless required by applicable law or agreed to in writing, software</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * distributed under the License is distributed on an "AS IS" BASIS,</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * See the License for the specific language governing permissions and</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * limitations under the License.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alteven"> </pre><pre class="alt">package org.springframework.web.context;</pre><pre class="alteven"> </pre><pre class="alt">import javax.servlet.ServletContextEvent;</pre><pre class="alteven">import javax.servlet.ServletContextListener;</pre><pre class="alt"> </pre><pre class="alteven"><span id="wmqeeuq" class="rem">/**</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * Bootstrap listener to start up Spring's root {@link WebApplicationContext}.</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * Simply delegates to {@link ContextLoader}.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> *</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * <p>This listener should be registered after</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * {@link org.springframework.web.util.Log4jConfigListener}</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * in <code>web.xml</code>, if the latter is used.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> *</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * @author Juergen Hoeller</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * @since 17.02.2003</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * @see ContextLoaderServlet</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * @see org.springframework.web.util.Log4jConfigListener</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alt"><span id="wmqeeuq" class="kwrd">public</span> <span id="wmqeeuq" class="kwrd">class</span> ContextLoaderListener implements ServletContextListener {</pre><pre class="alteven"> </pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">private</span> ContextLoader contextLoader;</pre><pre class="alteven"> </pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="rem">/**</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * Initialize the root web application context.</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">public</span> <span id="wmqeeuq" class="kwrd">void</span> contextInitialized(ServletContextEvent <span id="wmqeeuq" class="kwrd">event</span>) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">this</span>.contextLoader = createContextLoader();</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">this</span>.contextLoader.initWebApplicationContext(<span id="wmqeeuq" class="kwrd">event</span>.getServletContext());</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="rem">/**</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * Create the ContextLoader to use. Can be overridden in subclasses.</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * @return the new ContextLoader</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">protected</span> ContextLoader createContextLoader() {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">return</span> <span id="wmqeeuq" class="kwrd">new</span> ContextLoader();</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="rem">/**</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> * Return the ContextLoader used by this listener.</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * @return the current ContextLoader</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">public</span> ContextLoader getContextLoader() {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">return</span> <span id="wmqeeuq" class="kwrd">this</span>.contextLoader;</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven"> </pre><pre class="alt"> <span id="wmqeeuq" class="rem">/**</span></pre><pre class="alteven"><span id="wmqeeuq" class="rem"> * Close the root web application context.</span></pre><pre class="alt"><span id="wmqeeuq" class="rem"> */</span></pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">public</span> <span id="wmqeeuq" class="kwrd">void</span> contextDestroyed(ServletContextEvent <span id="wmqeeuq" class="kwrd">event</span>) {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">if</span> (<span id="wmqeeuq" class="kwrd">this</span>.contextLoader != <span id="wmqeeuq" class="kwrd">null</span>) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">this</span>.contextLoader.closeWebApplicationContext(<span id="wmqeeuq" class="kwrd">event</span>.getServletContext());</pre><pre class="alt"> }</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven">}</pre></div></div> <p>此类implement了ServletContextListener的两个方法:</p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="kwrd">public</span> <span id="wmqeeuq" class="kwrd">void</span> contextInitialized(ServletContextEvent <span id="wmqeeuq" class="kwrd">event</span>);</pre><pre class="alteven"><span id="wmqeeuq" class="kwrd">public</span> <span id="wmqeeuq" class="kwrd">void</span> contextDestroyed(ServletContextEvent <span id="wmqeeuq" class="kwrd">event</span>);</pre></div></div> <p>分别做context的初始化和销?/p> <p>另外提供了一个protectedҎQprotected ContextLoader createContextLoader()  用于创徏真正做事情的代理cCotextLoader</p> <p>和一个publicҎQpublic ContextLoader getContextLoader()Q?/p> <p> </p> <p>可见Q这个Listenercȝ接将工作<strong><u>代理</u></strong>l了ContextLoadercM</p> <p> </p> <p>____________________________________________________________________________________________________________________________</p> <p>我们按图索骥Q下面再分析org.springframework.web.context.ContextLoader</p> <p>ContextLoader里面有个U有成员Qprivate WebApplicationContext context</p> <p>此变量提供了createҎQ?/p> <p>createWebApplicationContext(ServletContext servletContext, ApplicationContext parent) <p>因ؓSpring提供了多UWebApplicationContextc,所以需要一个方法来军_使用哪个WebApplicationContextContextc?/p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="kwrd">protected</span> Class determineContextClass(ServletContext servletContext) throws ApplicationContextException {</pre><pre class="alteven"> String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">if</span> (contextClassName != <span id="wmqeeuq" class="kwrd">null</span>) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">try</span> {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">return</span> ClassUtils.forName(contextClassName);</pre><pre class="alteven"> }</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">catch</span> (ClassNotFoundException ex) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">throw</span> <span id="wmqeeuq" class="kwrd">new</span> ApplicationContextException(</pre><pre class="alt"> <span id="wmqeeuq" class="str">"Failed to load custom context class ["</span> + contextClassName + <span id="wmqeeuq" class="str">"]"</span>, ex);</pre><pre class="alteven"> }</pre><pre class="alt"> }</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">else</span> {</pre><pre class="alt"> contextClassName = defaultStrategies.getProperty(WebApplicationContext.<span id="wmqeeuq" class="kwrd">class</span>.getName());</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">try</span> {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">return</span> ClassUtils.forName(contextClassName, ContextLoader.<span id="wmqeeuq" class="kwrd">class</span>.getClassLoader());</pre><pre class="alteven"> }</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">catch</span> (ClassNotFoundException ex) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">throw</span> <span id="wmqeeuq" class="kwrd">new</span> ApplicationContextException(</pre><pre class="alt"> <span id="wmqeeuq" class="str">"Failed to load default context class ["</span> + contextClassName + <span id="wmqeeuq" class="str">"]"</span>, ex);</pre><pre class="alteven"> }</pre><pre class="alt"> }</pre><pre class="alteven"> }</pre></div></div> <p> </p> <p>public static final String CONTEXT_CLASS_PARAM = "contextClass";</p> <p>所以如果在web.xml中的<context-param> </context-param>中定义了参数contextClassQ那么直接就军_了用此Contextc?/p> <p>否则Q就应用~省{略来决定用哪个ContextcR?/p> <p>~省{略如下Q?/p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="kwrd">private</span> <span id="wmqeeuq" class="kwrd">static</span> final Properties defaultStrategies;</pre><pre class="alteven"> </pre><pre class="alt"><span id="wmqeeuq" class="kwrd">static</span> {</pre><pre class="alteven"> <span id="wmqeeuq" class="rem">// Load default strategy implementations from properties file.</span></pre><pre class="alt"> <span id="wmqeeuq" class="rem">// This is currently strictly internal and not meant to be customized</span></pre><pre class="alteven"> <span id="wmqeeuq" class="rem">// by application developers.</span></pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">try</span> {</pre><pre class="alteven"> ClassPathResource resource = <span id="wmqeeuq" class="kwrd">new</span> ClassPathResource(DEFAULT_STRATEGIES_PATH, ContextLoader.<span id="wmqeeuq" class="kwrd">class</span>);</pre><pre class="alt"> defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);</pre><pre class="alteven"> }</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">catch</span> (IOException ex) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">throw</span> <span id="wmqeeuq" class="kwrd">new</span> IllegalStateException(<span id="wmqeeuq" class="str">"Could not load 'ContextLoader.properties': "</span> + ex.getMessage());</pre><pre class="alt"> }</pre><pre class="alteven">}</pre></div></div> <p>实际上,~省{略从org\springframework\web\context\ContextLoader.properties 文g中取得属性org.springframework.web.context.WebApplicationContext</p> <p>我们看看ContextLoader.properties文g的内容:</p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"># Default WebApplicationContext implementation <span id="wmqeeuq" class="kwrd">class</span> <span id="wmqeeuq" class="kwrd">for</span> ContextLoader.</pre><pre class="alteven"># Used <span id="wmqeeuq" class="kwrd">as</span> fallback when no <span id="wmqeeuq" class="kwrd">explicit</span> context implementation has been specified <span id="wmqeeuq" class="kwrd">as</span> context-param.</pre><pre class="alt"># Not meant to be customized by application developers.</pre><pre class="alteven"> </pre><pre class="alt">org.springframework.web.context.WebApplicationContext=org.springframework.web.context.support.XmlWebApplicationContext</pre></div></div> <p>昄Q缺省的Contextcd?XmlWebApplicationContextc?/p> <p>Q!Q真累啊QSpring...</p> <p> </p> <p>OK,ȝ知道用哪个ContextcMQ那么现在到了createq个Context实例的时候了</p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="kwrd">protected</span> WebApplicationContext createWebApplicationContext(</pre><pre class="alteven"> ServletContext servletContext, ApplicationContext parent) throws BeansException {</pre><pre class="alt"> </pre><pre class="alteven"> Class contextClass = determineContextClass(servletContext);</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">if</span> (!ConfigurableWebApplicationContext.<span id="wmqeeuq" class="kwrd">class</span>.isAssignableFrom(contextClass)) {</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">throw</span> <span id="wmqeeuq" class="kwrd">new</span> ApplicationContextException(<span id="wmqeeuq" class="str">"Custom context class ["</span> + contextClass.getName() +</pre><pre class="alt"> <span id="wmqeeuq" class="str">"] is not of type ["</span> + ConfigurableWebApplicationContext.<span id="wmqeeuq" class="kwrd">class</span>.getName() + <span id="wmqeeuq" class="str">"]"</span>);</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven"> ConfigurableWebApplicationContext wac =</pre><pre class="alt"> (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);</pre><pre class="alteven"> wac.setParent(parent);</pre><pre class="alt"> wac.setServletContext(servletContext);</pre><pre class="alteven"> wac.setConfigLocation(servletContext.getInitParameter(CONFIG_LOCATION_PARAM));</pre><pre class="alt"> customizeContext(servletContext, wac);</pre><pre class="alteven"> wac.refresh();</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">return</span> wac;</pre><pre class="alt"> }</pre></div></div> <p>q里很容易理解,只不q它的创Z是直接newQ而是装了一层,调用BeanUtils.instantiateClass()工具Ҏ</p> <p>接下来设定WebApplicationCcontext实例的parent, servletContext, </p> <p>其中配置文g位置(web.xml?的contextConfigLocation参数指定?/p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><context-param></pre><pre class="alteven"> <param-name>contextConfigLocation</param-name></pre><pre class="alt"> <param-<span id="wmqeeuq" class="kwrd">value</span>>classpath:/SpringContext/applicationContext-web.xml</pre><pre class="alteven"> </param-<span id="wmqeeuq" class="kwrd">value</span>></pre><pre class="alt"></context-param></pre></div></div> <p>倒数W二行调用的customizeContext()Ҏ目前Spring实现代码是空的,估计留作以后Q看来万事要留余地啊^_^Q?/p> <p>最后一件事是调用WebApplicationContext?font color="#ff0000" size="4"><u>refresh()</u></font>Ҏ。(q个Ҏ是个stratupҎQ很重要。他q的事情后面会着重涉及)</p> <p> </p> <p>最后就是真正做事的initWebApplicationContext()ҎQ?/p> <div id="wmqeeuq" class="csharpcode-wrapper"> <div id="wmqeeuq" class="csharpcode"><pre class="alt"><span id="wmqeeuq" class="kwrd">public</span> WebApplicationContext initWebApplicationContext(ServletContext servletContext)</pre><pre class="alteven"> throws IllegalStateException, BeansException {</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">if</span> (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != <span id="wmqeeuq" class="kwrd">null</span>) {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">throw</span> <span id="wmqeeuq" class="kwrd">new</span> IllegalStateException(</pre><pre class="alteven"> <span id="wmqeeuq" class="str">"Cannot initialize context because there is already a root application context present - "</span> +</pre><pre class="alt"> <span id="wmqeeuq" class="str">"check whether you have multiple ContextLoader* definitions in your web.xml!"</span>);</pre><pre class="alteven"> }</pre><pre class="alt"> </pre><pre class="alteven"> servletContext.log(<span id="wmqeeuq" class="str">"Initializing Spring root WebApplicationContext"</span>);</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">if</span> (logger.isInfoEnabled()) {</pre><pre class="alteven"> logger.info(<span id="wmqeeuq" class="str">"Root WebApplicationContext: initialization started"</span>);</pre><pre class="alt"> }</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">long</span> startTime = System.currentTimeMillis();</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">try</span> {</pre><pre class="alt"> <span id="wmqeeuq" class="rem">// Determine parent for root web application context, if any.</span></pre><pre class="alteven"> ApplicationContext parent = loadParentContext(servletContext);</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="rem">// Store context in local instance variable, to guarantee that</span></pre><pre class="alt"> <span id="wmqeeuq" class="rem">// it is available on ServletContext shutdown.</span></pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">this</span>.context = createWebApplicationContext(servletContext, parent);</pre><pre class="alt"> servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, <span id="wmqeeuq" class="kwrd">this</span>.context);</pre><pre class="alteven"> currentContextPerThread.put(Thread.currentThread().getContextClassLoader(), <span id="wmqeeuq" class="kwrd">this</span>.context);</pre><pre class="alt"> </pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">if</span> (logger.isDebugEnabled()) {</pre><pre class="alt"> logger.debug(<span id="wmqeeuq" class="str">"Published root WebApplicationContext as ServletContext attribute with name ["</span> +</pre><pre class="alteven"> WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + <span id="wmqeeuq" class="str">"]"</span>);</pre><pre class="alt"> }</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">if</span> (logger.isInfoEnabled()) {</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">long</span> elapsedTime = System.currentTimeMillis() - startTime;</pre><pre class="alteven"> logger.info(<span id="wmqeeuq" class="str">"Root WebApplicationContext: initialization completed in "</span> + elapsedTime + <span id="wmqeeuq" class="str">" ms"</span>);</pre><pre class="alt"> }</pre><pre class="alteven"> </pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">return</span> <span id="wmqeeuq" class="kwrd">this</span>.context;</pre><pre class="alteven"> }</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">catch</span> (RuntimeException ex) {</pre><pre class="alteven"> logger.error(<span id="wmqeeuq" class="str">"Context initialization failed"</span>, ex);</pre><pre class="alt"> servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">throw</span> ex;</pre><pre class="alt"> }</pre><pre class="alteven"> <span id="wmqeeuq" class="kwrd">catch</span> (Error err) {</pre><pre class="alt"> logger.error(<span id="wmqeeuq" class="str">"Context initialization failed"</span>, err);</pre><pre class="alteven"> servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);</pre><pre class="alt"> <span id="wmqeeuq" class="kwrd">throw</span> err;</pre><pre class="alteven"> }</pre><pre class="alt"> }</pre></div></div> <p>它其实做得事情很单,调用loadParentContext()Ҏ获取父context,调用createWebApplicationContext()创徏WebApplicationContext实例</p> <p> </p> <p>一切都g完成了,臛_我们明白了配|文件是如何加蝲q去的,至于IoC容器如何帮你注入配置文g中的beanQ下ơ再探烦。线索是什么呢Q你q记得在createWebApplication()的最后一步做什么了吗?refresh(), 对了Q这个就是你作ؓ职业"嘿客"要探索的下一个线?/p><img src ="http://www.aygfsteel.com/charles/aggbug/248497.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/charles/" target="_blank">suprasoft Inc,.</a> 2008-12-26 16:53 <a href="http://www.aygfsteel.com/charles/archive/2008/12/26/248497.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PO BO VO DTO POJO DAO概念及其作用Q附转换图)http://www.aygfsteel.com/charles/archive/2008/12/26/248418.htmlsuprasoft Inc,.suprasoft Inc,.Fri, 26 Dec 2008 04:53:00 GMThttp://www.aygfsteel.com/charles/archive/2008/12/26/248418.htmlhttp://www.aygfsteel.com/charles/comments/248418.htmlhttp://www.aygfsteel.com/charles/archive/2008/12/26/248418.html#Feedback0http://www.aygfsteel.com/charles/comments/commentRss/248418.htmlhttp://www.aygfsteel.com/charles/services/trackbacks/248418.htmlJ2EE开发中大量的专业羃略语很是让hqhQ尤其是跟一些高手讨论问题的时候,三分钟就被h家满口的专业术语h了,PO VO BO DTO POJO DAOQ一大堆的就来了Q听q老罗对这U现象的批判的朋友会会心一W)?

    首先声明偶也不是什么高手,以下ȝ都是自己的体会。不对之处请您多指教?

POQ?br>persistant object持久对象
最形象的理解就是一个PO是数据库中的一条记录?br>好处是可以把一条记录作Z个对象处理,可以方便的{为其它对象?


BOQ?br>business object业务对象
主要作用是把业务逻辑装Z个对象。这个对象可以包括一个或多个其它的对象?br>比如一个简历,有教育经历、工作经历、社会关pȝ{?br>我们可以把教育经历对应一个POQ工作经历对应一个POQ社会关pd应一个PO?br>建立一个对应简历的BO对象处理历,每个BO包含q些PO?br>q样处理业务逻辑Ӟ我们可以针对BOd理?


VO Q?br>value object值对?br>ViewObject表现层对?br>主要对应界面昄的数据对象。对于一个WEB面Q或者SWT、SWING的一个界面,用一个VO对象对应整个界面的倹{?


DTO Q?br>Data Transfer Object数据传输对象
主要用于q程调用{需要大量传输对象的地方?br>比如我们一张表?00个字D,那么对应的PO有100个属性?br>但是我们界面上只要显C?0个字D,
客户端用WEB service来获取数据,没有必要把整个PO对象传递到客户端,
q时我们可以用只有q?0个属性的DTO来传递结果到客户端,q样也不会暴露服务端表结?到达客户端以后,如果用这个对象来对应界面昄Q那此时它的w䆾p{为VO


POJO Q?br>plain ordinary java object 单java对象
个h感觉POJO是最常见最多变的对象,是一个中间对象,也是我们最常打交道的对象?br>一个POJO持久化以后就是PO
直接用它传递、传递过E中是DTO
直接用来对应表示层就是VO


DAOQ?br>data access object数据讉K对象
q个大家最熟悉Q和上面几个O区别最大,基本没有互相转化的可能性和必要.
主要用来装Ҏ据库的访问。通过它可以把POJO持久化ؓPOQ用POl装出来VO、DTO
      ȝ下我认ؓ一个对象究竟是什么O要看具体环境Q在不同的层、不同的应用场合Q对象的w䆾也不一P而且对象w䆾的{化也是很自然的。就像你对老婆来说是老公Q对父母来说是子女。设计这些概늚初衷不是Z唬h而是Z更好的理解和处理各种逻辑Q让大家能更好的ȝ面向对象的方式处理问?
      大家千万不要陷入q度设计Q大可不必ؓ了设计而设计一定要在代码中区分各个对象。一句话技术是为应用服务的?br>Ƣ迎指正?



M个图Q感觉没有完全表辑և自己的意思。。。。。谁帮忙完善下,最好能体现各个O在MVC中的位置
snap20070108.jpg

suprasoft Inc,. 2008-12-26 12:53 发表评论
]]>
web.xml详解http://www.aygfsteel.com/charles/archive/2008/12/26/248402.htmlsuprasoft Inc,.suprasoft Inc,.Fri, 26 Dec 2008 03:34:00 GMThttp://www.aygfsteel.com/charles/archive/2008/12/26/248402.htmlhttp://www.aygfsteel.com/charles/comments/248402.htmlhttp://www.aygfsteel.com/charles/archive/2008/12/26/248402.html#Feedback0http://www.aygfsteel.com/charles/comments/commentRss/248402.htmlhttp://www.aygfsteel.com/charles/services/trackbacks/248402.html每一个站的WEB-INF下都有一个web.xml的设定文Ӟ它提供了我们站台的配|设?

web.xml定义Q?br>.站台的名U和说明
.针对环境参数(Context)做初始化工作
.Servlet的名U和映射
.Session的设?br>.Tag library的对?br>.JSP|页讑֮
.Mime Type处理
.错误处理
.利用JDNI取得站台资源

要了解web.xml的设定|必须了解它的schema,从web.xml中知道它的schema是由Sum Microsystems公司定制的,如果你想更ؓ详细的了解它Q?br>可以?a >http://java.sun.com/xml/ns/j2ee/web-mapp_2_4.xsd|页Q那里有更ؓ详细的介l。这里我介绍我们q_见得最多的.

   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>


q是一般在写XML时所做的声明,定义了XML的版本,~码格式,q有重要的指明schema的来??a >http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd.

<description>,<display-name>,<icon>
____________________________________________

<description>站台描述</discription>
对站台做出描q?

<display-name>站台名称</display-name>
定义站台的名U?

<icon>
icon元素包含small-icon和large-icon两个子元?用来指定web站台中小图标和大图标的\?
<small-icon>/路径/smallicon.gif</small-icon>
small-icon元素应指向web站台中某个小图标的\?大小?6 X 16 pixel,但是图象文g必须为GIF或JPEG格式,扩展名必Mؓ:.gif?jpg.

<large-icon>/路径/largeicon-jpg</large-icon>
large-icon元素应指向web站台中某个大图表路径,大小?2 X 32 pixel,但是图象文g必须为GIF或JPEG的格?扩展名必Mؓ; gif
或jpg.
范例:

   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>
______________________________________
distributable 元素为空标签,它的存在与否可以指定站台是否可分布式处理.如果web.xml中出现这个元?则代表站台在开发时已经
被设计ؓ能在多个JSP Container 之间分散执行.
范例:

   1: <distributable/> 

 

 

 

<context-param>
___________________________________

<context-param>
context-param 元素用来讑֮web站点?u>环境参数(context),它包含两个子元素:
param-name和param-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>


此所讑֮的参?在JSP|页中可以用下列方法来取得:

   1: ${initParam.param_name}


若在Servlet可以使用下列Ҏ来获?

   1: String param_name=getServletContext().getInitParamter("param_name"); 

又如Spring framework在这里可以设|context参数

   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的相兌?filter元素除了下面介绍的的子元素之?q包?lt;servlet>介绍q的<icon>,<display-name>
,<description>,<init-param>,其用途一?
<filter-name>Filter的名U?lt;/filter-name>
定义Filter的名U?
<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>

又如Struts2可以在这里设filter

   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-mapping 元素的两个主要子元素filter-name和url-pattern.用来定义Filter所对应的URL.
<filter-name>Filter的名U?lt;/filter-name>
定义Filter的名U?
<url-pattern>URL</url-pattern>
Filter所对应的RUL.例如:<url-pattern>/Filter/Hello</url-pattern>

<servlet-name>Servlet的名U?lt;servlet-name>
定义servlet的名U?
<dispatcher>REQUEST|INCLUDE|FORWARD|ERROR</disaptcher>
讑֮Filter对应的请求方?有RQUEST,INCLUDE,FORWAR,ERROR四种,默认为REQUEST.
</filter-mapping>
范例:

   1: <filter-mapping>
   2:    <filter-name>GZIPEncoding</filter-name>
   3:    <url-pattern>/*</url-pattern>
   4: </filter-mapping> 

 

 

 

<servlet>

___________________________________________

<servlet-name>servlet的名U?lt;/servlet-name>

<display-name>昄名称</display-name>
<servlet-class>servlet对应的class?lt;/servlet-class>

范例Q?/p>

   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>
_____________________________________________
servlet-mapping元素包含两个子元素servlet-name和url-pattern.用来定义servlet所对应URL.
<servlet-name>Servlet的名U?lt;/servlet-name>
定义Servlet的名U?
<url-pattern>Servlet URL</url-pattern>
定义Servlet所对应的RUL.例如:<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接口,它的主要子元素ؓ<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> 

又如Spring framework可以在这里设listener

   1: <listener>
   2:     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   3: </listener>

 

 

 

<session-cofing>
__________________________________
<session-config>
session-config包含一个子元素session-timeout.定义web站台中的session参数.
<session-timeout>分钟</session-timeout>
定义q个web站台所有session的有效期?单位为分?
</session-config>
范例:

   1: <session-config>
   2:    <session-timeout>20</session-timeout>
   3: </session-config> 


 

 

 

<mime-mapping>
___________________________________________________
<mima-mapping>
mime-mapping包含两个子元素extension和mime-type.定义某一个扩展名和某一MIME Type做对?
<extension>扩展名名U?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-list包含一个子元素welcome-file.用来定义首页列单.
<welcome-file>用来指定首页文g名称</welcome-flie>
welcome-file用来指定首页文g名称.我们可以?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>
error-page元素包含三个子元素error-code,exception-type和location.错误代?Error Code)或异?Exception)的种cd?br>到web站台资源路径.
<error-code>错误代码</error-code>
HTTP Error code,例如: 404
<exception-type>Exception</exception-type>
一个完整名U的Java异常cd
<location>/路径</location>
在web站台内的相关资源路径
</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-config元素主要用来讑֮JSP的相关配|?<jsp:config>包括<taglib>?lt;jsp-property-group>两个子元?其中<taglib>元素
在JSP 1.2时就已经存在??lt;jsp-property-group>是JSP 2.0新增的元?

<taglib>
taglib元素包含两个子元素taglib-uri和taglib-location.用来讑֮JSP|页用到的Tag Library路径.
<taglib-uri>URI</taglib-uri>
   taglib-uri定义TLD文g的URI,JSP|页的taglib指o可以l由q个URI存取到TLD文g.
<taglib-location>/WEB-INF/lib/xxx.tld</taglib-laction>
   TLD文g对应Web站台的存放位|?
</taglib>

<jsp-property-group>
jsp-property-group元素包含8个元?分别?
<description>Description</descrition>
此设定的说明

<display-name>Name</display-name>
此设定的名称

<url-pattern>URL</url-pattern>
讑֮值所影响的范??/CH2 或?*.jsp

<el-ignored>true|false</el-ignored>
若ؓtrue,表示不支持EL语法.

<scripting-invalid>true|false</scripting-invalid>
若ؓtrue表示不支?lt;%scription%>语法.

<page-encoding>encoding</page-encoding>
讑֮JSP|页的编?

<include-prelude>.jspf</include-prelude>
讄JSP|页的抬?扩展名ؓ.jspf

<include-coda>.jspf</include-coda>
讄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>
resource-ref元素包括五个子元素description,res-ref-name,res-type,res-auth,res-sharing-scope.利用JNDI取得站点?br>利用资源.
<description>说明</description>
资源说明

<rec-ref-name>资源名称</rec-ref-name>
资源名称

<res-type>资源U类</res-type>
资源U类

<res-auth>Application|Container</res-auth>
资源由Application或Container来许?

<res-sharing-scope>Shareable|Unshareable</res-sharing-scope>
资源是否可以׃n.默认gؓ 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> 

q些都是些比较常用的,详细可以d: http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd



suprasoft Inc,. 2008-12-26 11:34 发表评论
]]>
POJO2VOhttp://www.aygfsteel.com/charles/archive/2008/12/25/248329.htmlsuprasoft Inc,.suprasoft Inc,.Thu, 25 Dec 2008 12:13:00 GMThttp://www.aygfsteel.com/charles/archive/2008/12/25/248329.htmlhttp://www.aygfsteel.com/charles/comments/248329.htmlhttp://www.aygfsteel.com/charles/archive/2008/12/25/248329.html#Feedback0http://www.aygfsteel.com/charles/comments/commentRss/248329.htmlhttp://www.aygfsteel.com/charles/services/trackbacks/248329.html最q用Flex做UI,但是和业务层不好l合Q特地写了个业务BO转VO的class

只需要指定需要生成的目录Q就可以扚w?BO.java转换?VO.as

代码如下Q?/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;// 其它cd的设|ؓ未知cd
  40:             } else {
  41:                 return typeName + "VO";// 自定义类型的Q加上VOl尾
  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文g
  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的vo对象名称l尾加上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:         // 包名Q没有设|包名就取和java pojo一L包名
 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: }


suprasoft Inc,. 2008-12-25 20:13 发表评论
]]>
վ֩ģ壺 㶫ʡ| ߱| ʲ| | | | ǡ| | ɽ| | | С| ܿ| | Դ| | | | | | ٳ| | ͨ| ʻ| | | | | °| | | | | | | ¹| | Դ| Ͻ| ۶| ˹|