问题描述:
我在网上查找了一些配置的例子,有好多配spring管理struts2的例子当中都没有配置 struts-config.xml文件,我以前也这样配过,但是现在把以前配好的例子拿出来运行,页面跳不过action里,这是为什么,上代码给大家
以下是web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
下边是struts.xml配置<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory.spring.autoWire" value="spring" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" >
<!--
<interceptors>
<interceptor name="testInter" class="com.test.interceptor.testInterceptor">
</interceptor>
<interceptor-stack name="defaults">
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
-->
<action name="login" class="dss">
<result name="SUCCESS" >/success.jsp</result>
<result name="input">/index.jsp</result>
<!-- <interceptor-ref name="testInter"></interceptor-ref>
<interceptor-ref name="defaults"></interceptor-ref>
-->
</action>
</package>
</struts>
下边是 /testStruts2/src/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dss" class="com.test.action.LoginAction" scope="prototype"></bean></beans>index.jsp文件如下<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<s:form action="login.action" method="post" theme="simple">
suserId<s:textfield name="user.userId"></s:textfield>
passward<s:textfield name="user.passWard"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form>
</body>
</html>action里边什么都没有,只有一个试验跳转的语句
package com.test.action;import com.opensymphony.xwork2.ActionSupport;
import com.test.models.User;public class LoginAction extends ActionSupport{ private User user;
public String login(){
//System.out.println(user.getPassWard());
System.out.println("使用action");
return "SUCCESS";
}
public String add(){
return "add";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void loginValidate(){
}
@Override
public void validate() {
this.addFieldError("user.userId", "useriderrpo");
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
//return super.execute();
//System.out.println(user.getPassWard());
System.out.println("使用的是excute的action");
return "SUCCESS";
}
}
请各位帮我看一下,为什么我的配置不能跳转进action里边
我在网上查找了一些配置的例子,有好多配spring管理struts2的例子当中都没有配置 struts-config.xml文件,我以前也这样配过,但是现在把以前配好的例子拿出来运行,页面跳不过action里,这是为什么,上代码给大家
以下是web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
下边是struts.xml配置<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.objectFactory.spring.autoWire" value="spring" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" >
<!--
<interceptors>
<interceptor name="testInter" class="com.test.interceptor.testInterceptor">
</interceptor>
<interceptor-stack name="defaults">
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
-->
<action name="login" class="dss">
<result name="SUCCESS" >/success.jsp</result>
<result name="input">/index.jsp</result>
<!-- <interceptor-ref name="testInter"></interceptor-ref>
<interceptor-ref name="defaults"></interceptor-ref>
-->
</action>
</package>
</struts>
下边是 /testStruts2/src/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dss" class="com.test.action.LoginAction" scope="prototype"></bean></beans>index.jsp文件如下<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<s:form action="login.action" method="post" theme="simple">
suserId<s:textfield name="user.userId"></s:textfield>
passward<s:textfield name="user.passWard"></s:textfield>
<s:submit value="submit"></s:submit>
</s:form>
</body>
</html>action里边什么都没有,只有一个试验跳转的语句
package com.test.action;import com.opensymphony.xwork2.ActionSupport;
import com.test.models.User;public class LoginAction extends ActionSupport{ private User user;
public String login(){
//System.out.println(user.getPassWard());
System.out.println("使用action");
return "SUCCESS";
}
public String add(){
return "add";
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void loginValidate(){
}
@Override
public void validate() {
this.addFieldError("user.userId", "useriderrpo");
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
//return super.execute();
//System.out.println(user.getPassWard());
System.out.println("使用的是excute的action");
return "SUCCESS";
}
}
请各位帮我看一下,为什么我的配置不能跳转进action里边
QQ36679697,或者是在回复中留下信箱,我给打包发过去