posts - 42, comments - 7, trackbacks - 0, articles - 1

          Servlet action is not available 問題解決

          Posted on 2008-03-29 21:09 TuringJava 閱讀(743) 評論(0)  編輯  收藏 所屬分類: Spring2.0
          環境eclipse3.2+myeclipse+tomcat5.0x

                 重要提示:出現這個問題的原因很多,最多見的是配置文件出錯不能初始化出現Servlet action is not available提示。要解決問題需要具體問題具體分析,多看容器的logs。

                 背景提示,我要做struts+spring+hibernate的配置,但是按照書上說的配置好了后,總是錯誤,提示Servlet action is not available后臺log就提示2006-03-22 22:34:09 StandardWrapperValve[action]: Servlet action is currently unavailable。弄了很久沒有弄好。后來看了很久的log才發現提示配置文件中有錯誤,所以把action設置為null。

          在找這個錯誤,找了很久才發現:一個是


              
          <plug-in
                  
          className="org.springframework.web.struts.ContextLoaderPlugIn">
                  
          <set-property property="contextConfigLocation"
                      value
          ="/WEB-INF/classes/applicationContext.xml" />
              
          </plug-in>

          在struts中配置spring插件時,applicationContext.xml(spring的配置文件)位置錯了,書上一般是"/WEB-INF/applicationContext.xml"  但是有的時候不是在這個下面。所以一定要自己到容器下看看具體位置。比如我的就是在web-inf/classes下。

             二是:在spring的配置文件下的插入hibernate的配置文件

              <bean id="SessionFactory"
                  class
          ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  
          <property name="configLocation">
                      
          <value>file:src/hibernate.cfg.xml</value>
                  
          </property>
              
          </bean>

          myeclipse自動添加的是這樣的,我一直沒有注意,結果應該為:

              <bean id="SessionFactory"
                  class
          ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                  
          <property name="configLocation">
                      
          <value>file:src/hibernate.cfg.xml</value>
                  
          </property>
              
          </bean>

          提示:hibernate.cfg.xml文件的具體位置你要到容器下去看。

          重要提示:

          1、還有就是一定要在struts配置文件中加: <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>。這樣你的action才能真的委托給spring。

          2、我發現我的myeclipse沒有把spring.jar拷貝到lib下,以后大家出了問題可以看看。

               利用spring+hibernate+struts過程中,發現一個問題,在action中將一個hibernate讀取出來的ArrayList存入session:request.getSession().setAttribute("treeFromRoot", treeList.iterator());

          在jsp中用標簽 讀取代碼如下:會出現Cannot create iterator for this collection 錯誤,弄了一下午都沒有搞定。

          <logic:notEmpty name="treeFromRoot">
             
          <logic:iterate type="edu.scnu.es.struts.vo.Tree" id="tree"
              name
          ="treeFromRoot">


             
          </logic:iterate>
            
          </logic:notEmpty> 

          最后決定用JSTL試一試,代碼改為:成功了。

          <c:forEach  items="${sessionScope.treeFromRoot}"  var="treeFromRoot1">
              ${treeFromRoot1.id };
          </c:forEach>

          其中:edu.scnu.es.struts.vo.Tree是treeFromRoot這個list的成員的原形類。


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


          網站導航:
           
          主站蜘蛛池模板: 宜君县| 淮阳县| 疏附县| 沅江市| 漳浦县| 化隆| 册亨县| 安远县| 甘孜县| 大渡口区| 阜新市| 罗平县| 甘谷县| 枞阳县| 盐亭县| 西畴县| 墨脱县| 彩票| 乡宁县| 三都| 五家渠市| 承德市| 虎林市| 图木舒克市| 廊坊市| 东城区| 旬阳县| 岑巩县| 濉溪县| 瑞昌市| 宁强县| 黄石市| 香港| 光山县| 彰武县| 竹山县| 威信县| 临潭县| 汕头市| 沙坪坝区| 姚安县|