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"
content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="test.do" method="post">
<input type="button" value="submit" onclick="doSubmit()">
</form>
</body>
</html>
5、js中
function doSubmit() {
alert("1");
var url = "/test.do?method=testAction";
$.get(url, function (data) {
alert("success");
});
}
为什么进入不到action中呢?请帮忙
[解决办法]
<form action="test.do" method="post">
1.action删了试试。
2.post你用的get,修改下。试试。
[解决办法]
或者是不是出404错误了?检查下url
[解决办法]
我记得struts1好像在配置的时候,要有一个代理吧!你的配置文件里,好像没有啊!