环境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的成员的原形类。