当前位置:编程学习 > JAVA >>

struts1 和 spring 整合问题

struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
       "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
       "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<action-mappings>
<action path="/aaa" scope="request" name="productTypeList">
<forward name="list" path="/test.jsp"/>
</action>
<action path="/bbb" forward="/index.jsp"></action>
</action-mappings>
<!-- 配置控制器 -->
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
</struts-config>
Action类代码:
@Controller("/aaa")
public class ProductTypeAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
ServletRequest request, ServletResponse response) throws Exception {
request.setAttribute("productType", "111");
return mapping.findForward("list");
}
}
web.xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>babashop</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>
                   org.springframework.web.context.ContextLoaderListener
                </listener-class>
</listener>
<servlet>
<servlet-name>struts1</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>struts1</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
最后请求地址:
http://localhost/bbb.do 可以得到正确的页面
http://localhost/aaa.do 得到的是一个空页面,也不报错,用火狐查看网络,返回的状态码是200。
怎么回事啊??? struts1 spring --------------------编程问答-------------------- 因为/bbb你是配置的forward属性,而/aaa是forward标签。你可以去了解这两个的区别 --------------------编程问答--------------------

可以看我的项目实例,希望对你有帮助拉
http://blog.csdn.net/shadowsick/article/details/8903278
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,