配置如下:struts-config.xml<action-mappings >
<action path="/test" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="head" path="/head.jsp" />
<forward name="error" path="/error.jsp" />
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<message-resources parameter="netstore.ApplicationResources" />
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
applicationContext.xml<bean name="/test" class="action.TestAction">
</bean>head.jsp
<form name="login" action="test.do">
<table>
<tr class="logintitle1">
<td>用户名<font color="red">*</font><input type="text" name="username"/></td>
<td><input type="submit" value="登录" onclick="return validate()"/></td>
</tr>
</form>testAction
public class TestAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("error");
}
<action path="/test" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="head" path="/head.jsp" />
<forward name="error" path="/error.jsp" />
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<message-resources parameter="netstore.ApplicationResources" />
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
applicationContext.xml<bean name="/test" class="action.TestAction">
</bean>head.jsp
<form name="login" action="test.do">
<table>
<tr class="logintitle1">
<td>用户名<font color="red">*</font><input type="text" name="username"/></td>
<td><input type="submit" value="登录" onclick="return validate()"/></td>
</tr>
</form>testAction
public class TestAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("error");
}
比如说只在struts配置文件中添加<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
并且所有action的类保持原样应该就可以了
楼上的意思是jar包的问题吗?我引入spring,spring-mock,spring—aspects这几个jar包
<forward name="head" path="/head.jsp" />
<forward name="error" path="/error.jsp" />
</action>
楼主看看这里,action没有name属性,这样Struts怎么会找到ActionForm进行操作呢?
testAction
public class TestAction extends DispatchAction { public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("error");
}
还是不行,但我把spring撤下去,可以正常运行。
web.xml 我没有更改。
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<struts-config>
<action-mappings>
<action path="/test"
type="org.springframework.web.struts.DelegatingActionProxy"
>
<forward name="error" path="/error.jsp" />
</action>
</action-mappings>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
</struts-config>
是jar包冲突了,当然也有配置多种方法引起的混乱。谢谢,结贴。