Struts1和Spring整合
1、struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<action-mappings >
<action name="test" path="/test" type="com.action.StudentManagerAction" parameter="method" scope="request" >
<forward name="chenggong" path="/chenggong.jsp" />
<forward name="shibai" path="/shibai.jsp" />
</action>
</action-mappings>
</struts-config>
2、action中
public class StudentManagerAction extends Action {
public ActionForward testAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
System.out.println("进来了");
try {
WebApplicationContext appContext = WebApplicationContextUtils
.getWebApplicationContext(this.getServlet()
.getServletContext());
StudentManagerService stdm = (StudentManagerService) appContext
.getBean("stdServiceManager");
stdm.bus_method();
return mapping.findForward("chenggong");
} catch (StudentManagerException e) {
System.err.println("action execute service exception!");
return mapping.findForward("shibai");
}
}
}
3、web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<servlet>
<servlet-name>action</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>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
4、jsp中
<html>
<head>
<script type="text/javascript" src="jqueryJS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/testSendData.js"></script>
<meta http-equiv="Content-Type"