Struts2 extends ActionSupport问题

肥添 2010-03-25 03:03:35
最近做一个项目,使用上啦ssh框架,使用ide为Myeclipise6.5

项目配置能够成功实现登录功能,但是,当Action 类继承ActionSupport的时候,发现页面的数据就传不到Action类,如果该类不继承ActionSupport就能够成功传递参数

将该工程使用eclipse 打开,仍然不可以,排除ide问题,

为什么当我继承ActionSupport时候直接写excuse方法能够成功接收数据,而继承后却不可以呢?

急。。。随时等到中。。。。。。。。。。。
...全文
1524 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
肥添 2010-03-29
  • 打赏
  • 举报
回复
将工程重新配置啦,没有办法
肥添 2010-03-27
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 bayougeng 的回复:]

这个问题真是蹊跷了。
你换个spring的版本试试呢。
[/Quote]

换个spring版本就是换jar包
肥添 2010-03-27
  • 打赏
  • 举报
回复
Spring 配置文件分的比较细,有四个,请大家看看。。

application-common.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">

<tx:attributes>

<tx:method name="send*" propagation="REQUIRED"/>
<tx:method name="read*" propagation="REQUIRED"/>

<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>



<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="write*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>

</tx:attributes>

</tx:advice>

<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* org.gdpu.*.*.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>


application-beans.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="noticeDao" class="org.gdpu.dao.impl.NoticeDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<bean id="personDao" class="org.gdpu.dao.impl.PersonDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

</beans>

application-actions.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">




<bean id="NoticeAction" class="org.gdpu.web.action.NoticeAction">
<property name="deanManager" ref="deanManager" />
<property name="teacherManager" ref="teacherManager" />
</bean>
<bean id="LoginAction" class="org.gdpu.web.action.LoginAction">
<property name="loginManager" ref="loginManager" />
</bean>


</beans>

application-services.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">



<bean id="deanManager" class="org.gdpu.service.impl.DeanManagerImpl">
<property name="noticeDao" ref="noticeDao">
</property>
</bean>

<bean id="teacherManager" class="org.gdpu.service.impl.TeacherManagerImpl">
<property name="noticeDao" ref="noticeDao">
</property>
</bean>

<bean id ="loginManager" class="org.gdpu.service.impl.LoginManagerImpl">
<property name="personDao">
<ref bean ="personDao"/>
</property>
</bean>
</beans>


就是这四个


bayougeng 2010-03-26
  • 打赏
  • 举报
回复
这个问题真是蹊跷了。
你换个spring的版本试试呢。
cy_gogo 2010-03-26
  • 打赏
  • 举报
回复
spring 的配置呢。 帖一下。
去掉spring可以运行成功,应该就是spring配置出错了
肥添 2010-03-26
  • 打赏
  • 举报
回复
估计是xml配置文件。
但是我的试过注析spring注入的类,struts.xml的action 不使用spring容器的,额外使用org.gdpu.**对应的action,仍然不可以接受数据(按理说应该把struts 和spring脱离关系啦)

但是如果我把spring脱离整个项目,去掉spring-struts整合包,当tomcat在启动时候不初始spring,这样单独
运行却能够成功

有谁可以留个邮箱后者qq,让我把工程发过去帮我改改?
happyfmy 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhangtian0710 的回复:]

仍然找原因中,发现如果不整合spring单纯使用struts使用时没有错误,能够传递参数的。。。
希望各位帮我找找原因
[/Quote]

spring的配置文件有没有用问题
肥添 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 bayougeng 的回复:]

你把action中的set和get方法去掉。
然后在代码中右键->生成set和get方法。
弄完以后重启服务器。
[/Quote]

get set 方法是自动生成的。不过还是尝试了一遍,不可以。

仍然不知道原因中
bayougeng 2010-03-25
  • 打赏
  • 举报
回复
你把action中的set和get方法去掉。
然后在代码中右键->生成set和get方法。
弄完以后重启服务器。
greatmind829 2010-03-25
  • 打赏
  • 举报
回复
换一个名称,试一试。。
肥添 2010-03-25
  • 打赏
  • 举报
回复
仍然找原因中,发现如果不整合spring单纯使用struts使用时没有错误,能够传递参数的。。。
希望各位帮我找找原因
肥添 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 bayougeng 的回复:]

你试试把页面上的form和text都用struts2的标签代替。
注意,页面顶端要加上:
<%@ taglib uri="/struts-tags" prefix="s" %>
[/Quote]

我试过使用struts2 的标签,测试action里面为String 型的test 继承了ActionSupport还是不能够传递

<h2>taglib</h2>
<s:form action="login">
<input type="text" name ="test" /><br>
<s:submit value="submit"></s:submit>
</s:form>

bayougeng 2010-03-25
  • 打赏
  • 举报
回复
你试试把页面上的form和text都用struts2的标签代替。
注意,页面顶端要加上:
<%@ taglib uri="/struts-tags" prefix="s" %>
肥添 2010-03-25
  • 打赏
  • 举报
回复
struts2配置文件

<?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" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> -->
<package name="yang" extends="struts-default">
<!-- 公共跳转的页面 -->
<global-results>
<result name="error">/WEB-INF/jsp/share/fail.jsp</result>
<result>/WEB-INF/jsp/share/success.jsp</result>
</global-results>

<!-- 初始化页面,包含公共模板页 -->
<action name="top"><result> /WEB-INF/jsp/share/top.jsp</result> </action>
<!-- 模板中,不同角色拥有不同的导航,位于页面的左边 -->
<action name="teacher_menu"> <result>/WEB-INF/jsp/teacher/teacher_menu.jsp</result> </action>
<action name="dean_menu"> <result>/WEB-INF/jsp/dean/dean_menu.jsp</result> </action>
<action name="content"> <result>/WEB-INF/jsp/share/content.jsp</result> </action>

<!-- 跳转到相关页面 forwardAction -->
<action name="toSendNotice"> <result>/WEB-INF/jsp/share/sendNotice.jsp</result> </action>

<!-- 处理与Notice相关的操作 -->
<action name="*Notice" class="NoticeAction" method="{1}">
<result name="success">/WEB-INF/jsp/share/success.jsp</result>
<result name="showNotice">/WEB-INF/jsp/share/showNotice.jsp</result>
</action>
<action name="login" class="LoginAction">
<result name="teacher">/WEB-INF/jsp/teacher/teacher_index.jsp</result>
<result name="dean">/WEB-INF/jsp/dean/dean_index.jsp</result>
</action>

</package>
</struts>

Action代码

package org.gdpu.web.action;

import org.gdpu.model.Person;
import org.gdpu.service.LoginManager;

import com.opensymphony.xwork2.ActionSupport;




//extends ActionSupport implements ServletRequestAware
public class LoginAction extends ActionSupport{

private String person;

private LoginManager loginManager;

// HttpServletRequest request;

public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
public void setLoginManager(LoginManager loginManager) {
this.loginManager = loginManager;
}
/*
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
*/
// public Person getPerson() {
// return person;
// }
//
// public void setPerson(Person person) {
// this.person = person;
// }
public String execute() throws Exception {

System.out.println(person);
// Person findPerson=loginManager.findPerson(person);

// if(findPerson!=null){
// //request.getSession().setAttribute("findPerson", findPerson);
// if("teacher".equals(findPerson.getJobTitle())){
// return "teacher";
// }else if("dean".equals(findPerson.getJobTitle())){
// return "dean";
// }else{
// return "error";
// }
// }else{
//
// return "error";
// }
return "teacher";
}
}


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>IEOA</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<welcome-file-list>
<welcome-file>/WEB-INF/jsp/share/index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application-*.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>




[code=jsp]
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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 'MyJsp.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>
<form action="login.action" method="post">
<input type="text" name ="person"><br>
<input type="submit" value="submit">
</form>
</body>
</html>

[/code]
肥添 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 applerockhool 的回复:]
贴代码吧,一定不是继承的原因,可能是其他的地方错了
[/Quote]
[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" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> -->
<package name="yang" extends="struts-default">
<!-- 公共跳转的页面 -->
<global-results>
<result name="error">/WEB-INF/jsp/share/fail.jsp</result>
<result>/WEB-INF/jsp/share/success.jsp</result>
</global-results>

<!-- 初始化页面,包含公共模板页 -->
<action name="top"><result> /WEB-INF/jsp/share/top.jsp</result> </action>
<!-- 模板中,不同角色拥有不同的导航,位于页面的左边 -->
<action name="teacher_menu"> <result>/WEB-INF/jsp/teacher/teacher_menu.jsp</result> </action>
<action name="dean_menu"> <result>/WEB-INF/jsp/dean/dean_menu.jsp</result> </action>
<action name="content"> <result>/WEB-INF/jsp/share/content.jsp</result> </action>

<!-- 跳转到相关页面 forwardAction -->
<action name="toSendNotice"> <result>/WEB-INF/jsp/share/sendNotice.jsp</result> </action>
[/xml]

[xml]
<!-- 处理与Notice相关的操作 -->
<action name="*Notice" class="NoticeAction" method="{1}">
<result name="success">/WEB-INF/jsp/share/success.jsp</result>
<result name="showNotice">/WEB-INF/jsp/share/showNotice.jsp</result>
</action>
<action name="login" class="LoginAction">
<result name="teacher">/WEB-INF/jsp/teacher/teacher_index.jsp</result>
<result name="dean">/WEB-INF/jsp/dean/dean_index.jsp</result>
</action>

</package>
</struts>
[/xml]
Action代码
[java]
package org.gdpu.web.action;

import org.gdpu.model.Person;
import org.gdpu.service.LoginManager;

import com.opensymphony.xwork2.ActionSupport;




//extends ActionSupport implements ServletRequestAware
public class LoginAction extends ActionSupport{

private String person;

private LoginManager loginManager;

// HttpServletRequest request;

public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
public void setLoginManager(LoginManager loginManager) {
this.loginManager = loginManager;
}
/*
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
*/
// public Person getPerson() {
// return person;
// }
//
// public void setPerson(Person person) {
// this.person = person;
// }
public String execute() throws Exception {

System.out.println(person);
// Person findPerson=loginManager.findPerson(person);

// if(findPerson!=null){
// //request.getSession().setAttribute("findPerson", findPerson);
// if("teacher".equals(findPerson.getJobTitle())){
// return "teacher";
// }else if("dean".equals(findPerson.getJobTitle())){
// return "dean";
// }else{
// return "error";
// }
// }else{
//
// return "error";
// }
return "teacher";
}
}
[/java]

为了找到原因,我不删减所有代码,请高手帮帮看看
BearKin 2010-03-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bayougeng 的回复:]
上代码。
[/Quote]
听梦哥的话
bayougeng 2010-03-25
  • 打赏
  • 举报
回复
上代码。
liuyanbei12 2010-03-25
  • 打赏
  • 举报
回复
看看要取的值页面和Action类型是否匹配,继承了ActionSupport以后,如果出现了类型不匹配,会自动拦截
applerockhool 2010-03-25
  • 打赏
  • 举报
回复
贴代码吧,一定不是继承的原因,可能是其他的地方错了

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧