Struts集成Spring出错:Servlet action is not available 的解决
2008-03-12 08:59
633 查看
Servlet action is not available
先讲讲如何把Struts和Spring给整合到一块去,提供还不会整的兄弟们参考参考,如果你只是关心上面提到的那个问题的解决,可以略过直接看最后面应该可以解决!
在Struts中集成Spring,把原来用户的请求由原来的Action直接处理变成请求先被Spring拦截,对Action所依赖的某些关系(如某个Action依赖某个Service)进行依赖注入后,再转到Action继续处理:
首先,先加载集成Spring的插件:就是在struts-config.xml配置文件中加入如下几行代码:
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
修改前的Action的如下:
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request"
type="com.custudio.cdman.ui.admin.struts.action.LoginAction">
</action>
对Action的修改通常有以下两种做法:
1、把type属性改为"org.springframework.web.struts.DelegatingActionProxy"
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
</action>
2、type属性可以保留原样不变,也可以直接删掉如下:
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request">
</action>
保留原样的原因只是方便以后查看时容易找出对应的处理请求的具体Action类
接着在struts-config.xml配置文件中加入<controller>字节点:
下面是把<controller>字节点附近的代码一起帖出来,目的是为了让大家知道<controller>字节点的位置,以免不必要的麻烦
<action forward="/WEB-INF/jsps/cdmgr/cdMgr.jsp"
path="/showCDMgrMain" />
<action forward="/WEB-INF/jsps/datamgr/dataMgr.jsp"
path="/showDataMgrMain" />
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<message-resources
parameter="com.custudio.cdman.ui.resource.ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
到 此struts-config.xml文件修改完成,接着就是如何让Spring在拦截用户的请求了,其实很新简单,只要把请求对应Action注册成 Spring的一个bean就可以了,仍以上面的那个Action为例,下面是applicationConfig.xml中的代码:
<!-- Service -->
<bean id="IOperatorService"
class="com.custudio.cdman.bussiness.sysadmin.OperatorServiceImpl"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="operatorDAO">
<ref bean="OperatorDAO" />
</property>
</bean>
<!-- Struts Action -->
<bean name="/login"
class="com.custudio.cdman.ui.admin.struts.action.LoginAction"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="operatorService">
<ref bean="IOperatorService" />
</property>
</bean>
注意 这个bean用的是name="/login",不能用id="..."之类的 !!!
通过上面几步就完成了对Struts和Spring的整合。
进入正题,解决Servlet action is not available 的问题,
其实就是一个很小的地方修改一下就OK了,当然前提是你的struts-config.xml和applicationContext.xml文件配置确认无误,还出现了上面提示的错误的话,那现在试着把jsp页面的Action对应的Form表单的属性action="xxx.do?method=..."改成action="/xxx.do?method=..."
先讲讲如何把Struts和Spring给整合到一块去,提供还不会整的兄弟们参考参考,如果你只是关心上面提到的那个问题的解决,可以略过直接看最后面应该可以解决!
在Struts中集成Spring,把原来用户的请求由原来的Action直接处理变成请求先被Spring拦截,对Action所依赖的某些关系(如某个Action依赖某个Service)进行依赖注入后,再转到Action继续处理:
首先,先加载集成Spring的插件:就是在struts-config.xml配置文件中加入如下几行代码:
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
修改前的Action的如下:
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request"
type="com.custudio.cdman.ui.admin.struts.action.LoginAction">
</action>
对Action的修改通常有以下两种做法:
1、把type属性改为"org.springframework.web.struts.DelegatingActionProxy"
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
</action>
2、type属性可以保留原样不变,也可以直接删掉如下:
<action attribute="LoginForm" name="LoginForm"
input="/WEB-INF/jsps/sysadmin/login.jsp" parameter="method"
path="/login" scope="request">
</action>
保留原样的原因只是方便以后查看时容易找出对应的处理请求的具体Action类
接着在struts-config.xml配置文件中加入<controller>字节点:
下面是把<controller>字节点附近的代码一起帖出来,目的是为了让大家知道<controller>字节点的位置,以免不必要的麻烦
<action forward="/WEB-INF/jsps/cdmgr/cdMgr.jsp"
path="/showCDMgrMain" />
<action forward="/WEB-INF/jsps/datamgr/dataMgr.jsp"
path="/showDataMgrMain" />
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
<message-resources
parameter="com.custudio.cdman.ui.resource.ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
到 此struts-config.xml文件修改完成,接着就是如何让Spring在拦截用户的请求了,其实很新简单,只要把请求对应Action注册成 Spring的一个bean就可以了,仍以上面的那个Action为例,下面是applicationConfig.xml中的代码:
<!-- Service -->
<bean id="IOperatorService"
class="com.custudio.cdman.bussiness.sysadmin.OperatorServiceImpl"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="operatorDAO">
<ref bean="OperatorDAO" />
</property>
</bean>
<!-- Struts Action -->
<bean name="/login"
class="com.custudio.cdman.ui.admin.struts.action.LoginAction"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="operatorService">
<ref bean="IOperatorService" />
</property>
</bean>
注意 这个bean用的是name="/login",不能用id="..."之类的 !!!
通过上面几步就完成了对Struts和Spring的整合。
进入正题,解决Servlet action is not available 的问题,
其实就是一个很小的地方修改一下就OK了,当然前提是你的struts-config.xml和applicationContext.xml文件配置确认无误,还出现了上面提示的错误的话,那现在试着把jsp页面的Action对应的Form表单的属性action="xxx.do?method=..."改成action="/xxx.do?method=..."
相关文章推荐
- Struts集成Spring出错:Servlet action is not available 的解决
- Struts集成Spring出错:Servlet action is not available 的解决
- Struts集成Spring出错:Servlet action is not available 的解决
- Struts集成Spring出错:Servlet action is not available 的解决
- 整合Spring+Hibernate+Struts时抛Servlet action is not available异常解决
- 用Spring集成Struts时老出Servlet action is not available错
- 用Spring集成Struts时老出Servlet action is not available
- ssh集成过程中针对Servlet action is not available的解决办法
- Servlet action is not available(Struts+Spring+Hibernate)
- Struts:HTTP Status 404 - Servlet action is not available
- struts常见问题1:HTTP Status 404 - Servlet action is not available
- 在部署Struts时,出现如下错误信息:HTTP Status 404 - Servlet action is not available
- 在struts-config.xml中配置validator-plugin导致404 Servlet action is not available
- Servlet Action is not available 错误的其他可能原因和解决方法
- Servlet Action is not available 错误的其他可能原因和解决方法
- Servlet action is not available 问题解决
- HTTP Status 404 - Servlet action is not available 解决方法[转]
- Servlet action is not available异常解决
- IIS7集成模式初始化Spring.NET容器(Request is not available in this context exception in Application_Start问题)
- description The requested resource (Servlet action is not available) is not available.