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

          Servlet action is not available 問題解決

          Posted on 2008-03-29 21:09 TuringJava 閱讀(742) 評論(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的成員的原形類。


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


          網站導航:
           
          主站蜘蛛池模板: 宜春市| 南充市| 丰顺县| 兴海县| 福贡县| 宝兴县| 巴塘县| 施秉县| 利川市| 宾阳县| 灵璧县| 敦煌市| 天全县| 兴化市| 鸡泽县| 奉节县| 平邑县| 汉中市| 岱山县| 顺平县| 旺苍县| 阜宁县| 合川市| 白山市| 商丘市| 比如县| 外汇| 铁岭市| 西安市| 林西县| 巴彦县| 新干县| 安阳县| 南召县| 贺州市| 珠海市| 颍上县| 太仆寺旗| 绥芬河市| 铁岭市| 汽车|