當(dāng)柳上原的風(fēng)吹向天際的時候...

          真正的快樂來源于創(chuàng)造

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
          將程序從一個容器換到另一個容器,總會有各種意料之外的困難需要解決,近日本人需要將一個Web工程從Tomcat環(huán)境轉(zhuǎn)移到WebSphere環(huán)境,經(jīng)歷了一番周折,特地將此經(jīng)過記錄下來,也許它能對將要進(jìn)行如此經(jīng)歷的人其一點幫助作用,另外在此也向網(wǎng)絡(luò)同仁和工作中的同事表示感謝。

          原環(huán)境:
          程序:SSH
          容器:Tomcat6.0
          數(shù)據(jù)庫:MySql5

          新環(huán)境:
          程序:SSH
          容器:WebSphere6.1
          數(shù)據(jù)庫:Oracle10g

          移植過程中的第一個困難,是WebSphere不認(rèn)識Web.xml中的Struts taglib.原文字(適用于Tomcat)如下:
          <!-- Struts的TLDS -->
              
          <taglib>
                  
          <taglib-uri>/WEB-INF/tld/app.tld</taglib-uri>
                  
          <taglib-location>/WEB-INF/tld/app.tld</taglib-location>
              
          </taglib>

              
          <!-- Struts Tag Library Descriptors -->
              
          <taglib>
                  
          <taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
                  
          <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
              
          </taglib>

              
          <taglib>
                  
          <taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
                  
          <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
              
          </taglib>

              
          <taglib>
                  
          <taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
                  
          <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
              
          </taglib>

          這個問題因為之前有所準(zhǔn)備,在網(wǎng)絡(luò)上找到了答案,將上述文字包在<jsp-config>節(jié)點中即可,修改后(對Tomcat和WebSphere均適用)的文字如下:
          <!-- Struts的TLDS -->
              
          <jsp-config>
                  
          <taglib>
                      
          <taglib-uri>/WEB-INF/tld/app.tld</taglib-uri>
                      
          <taglib-location>/WEB-INF/tld/app.tld</taglib-location>
                  
          </taglib>

                  
          <!-- Struts Tag Library Descriptors -->
                  
          <taglib>
                      
          <taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
                      
          <taglib-location>
                          /WEB-INF/tld/struts-bean.tld
                      
          </taglib-location>
                  
          </taglib>

                  
          <taglib>
                      
          <taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
                      
          <taglib-location>
                          /WEB-INF/tld/struts-html.tld
                      
          </taglib-location>
                  
          </taglib>

                  
          <taglib>
                      
          <taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
                      
          <taglib-location>
                          /WEB-INF/tld/struts-logic.tld
                      
          </taglib-location>
                  
          </taglib>
              
          </jsp-config>

          如此處理后,首頁顯示出來了,隨即翻頁遇到了問題,在IE中是翻頁出現(xiàn)404錯誤,在FF中好一點,它告訴我WebSphere無法解析struts配置文件struts-config.xml。
          起初我以為是中文問題,刪除struts-config.xml中所有中文注釋問題依舊,接下來在網(wǎng)絡(luò)中尋找,還真有和我遇到一樣問題的難友,但沒人提出解決方案,正在撓頭之際,我們的PM忽然說是否JDK不一致,檢查一下,本機(jī)用的是1.6,而WebSphere自帶1.5的,將本機(jī)也調(diào)成1.5后,問題解決! 真是只有咒語能解開咒語。

          再下來,在表單提交時遇到了亂碼問題,這是因為之前聽信網(wǎng)絡(luò)意見,將Web.xml中的filter都去掉了,結(jié)果自然亂碼。此時感覺網(wǎng)絡(luò)傳聞未必可信,于是將filter又重新加上,亂碼沒有了。看來不經(jīng)親自嘗試而盲從網(wǎng)絡(luò)傳聞是要吃虧的。

          再下來,程序要訪問數(shù)據(jù)庫了,于是在WebSphere6.1中設(shè)置了數(shù)據(jù)源,再在Spring配置文件中進(jìn)行了設(shè)置,如下:
          <bean id="dataSource"
                  class
          ="org.springframework.jndi.JndiObjectFactoryBean">
                  
          <property name="jndiName"
                      value
          ="java:comp/env/jdbc/*******DS">
                  
          </property>
          </bean> 


          這樣寫在Tomcat中好用,在WebSphere不好用,正在撓頭之際,PM告我別的項目有同樣的寫法,于是一看,java:comp/env/這部分是不需要的,直接把數(shù)據(jù)源JNDI名寫在Value中就可以了。
          <bean id="dataSource"
                  class
          ="org.springframework.jndi.JndiObjectFactoryBean">
                  
          <property name="jndiName"
                      value
          ="jdbc/*******DS">
                  
          </property>
          </bean> 

          其它數(shù)據(jù)庫移植的問題就交給了Hibernate。至此問題全部解決。

          事后來看,WebSphere6.1對中文,SSH的支持還是很好的,只是有些特定的地方和傳統(tǒng)的Tomcat中的項目不太一樣,注意一下就好了,未必有想象中的困難。遇到困難時,向有同樣經(jīng)歷的人請教比自己在網(wǎng)絡(luò)上搜尋要快很多。
          posted on 2011-03-16 22:43 何楊 閱讀(420) 評論(2)  編輯  收藏

          Feedback

          # re: 只有咒語能解開咒語--談一次Web工程的移植 2011-03-31 16:52 鮑國鈺
          Tomcat6向Weblogic10.3移植,
          SQLServer2005向Oracle10g數(shù)據(jù)庫轉(zhuǎn)換折磨了我一個多月。最終還是自己寫
          了個輪子。二進(jìn)制數(shù)據(jù)比較麻煩。  回復(fù)  更多評論
            

          # re: 只有咒語能解開咒語--談一次Web工程的移植 2011-04-05 21:53 何楊的股票博客
          @鮑國鈺

          有時候捷徑反而是最遠(yuǎn)的,看似笨辦法卻是最好的。  回復(fù)  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 离岛区| 古丈县| 高安市| 南汇区| 宜宾县| 甘孜县| 康乐县| 长寿区| 蕉岭县| 鲁山县| 宣威市| 都江堰市| 临泉县| 绥芬河市| 榕江县| 安徽省| 芒康县| 岱山县| 中山市| 伊宁县| 资源县| 怀柔区| 崇州市| 盈江县| 抚宁县| 乾安县| 谷城县| 监利县| 攀枝花市| 梁平县| 平南县| 五莲县| 嵊州市| 来安县| 长春市| 江孜县| 峨眉山市| 莱芜市| 大石桥市| 科尔| 柯坪县|