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
          環(huán)境eclipse3.2+myeclipse+tomcat5.0x

                 重要提示:出現(xiàn)這個問題的原因很多,最多見的是配置文件出錯不能初始化出現(xiàn)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才發(fā)現(xiàn)提示配置文件中有錯誤,所以把action設(shè)置為null。

          在找這個錯誤,找了很久才發(fā)現(xiàn):一個是


              
          <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自動添加的是這樣的,我一直沒有注意,結(jié)果應(yīng)該為:

              <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、我發(fā)現(xiàn)我的myeclipse沒有把spring.jar拷貝到lib下,以后大家出了問題可以看看。

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

          在jsp中用標簽 讀取代碼如下:會出現(xiàn)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的成員的原形類。


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 清远市| 涿鹿县| 柳州市| 灵寿县| 若尔盖县| 阆中市| 鄯善县| 抚顺市| 张家界市| 伊金霍洛旗| 通渭县| 高州市| 偏关县| 通化市| 含山县| 阳信县| 合川市| 哈巴河县| 赤峰市| 通化市| 冕宁县| 大冶市| 威海市| 稷山县| 崇阳县| 石台县| 甘洛县| 蒲江县| 南皮县| 常宁市| 沭阳县| 凤山县| 台中市| 兴宁市| 贵州省| 兴仁县| 兴义市| 安顺市| 康定县| 清丰县| 岳阳市|