s2sh中struts2的页面的值无法传的action中,相当头痛……

问题描述

代码我给大家贴过来,希望大家多费心帮忙看看,谢谢了……===========================================[color=#FF0000]Things.java[/color]___________________________________________package com.lg.bean;import java.util.Date;public class Things { private Integer id; private String name ; private Date date ; private Integer money; private Integer dvalue; private Integer mvalue ; private Group group ; private Integer gid ; public Integer getId() {  return id; } public void setId(Integer id) {  this.id = id; } public String getName() {  return name; } public void setName(String name) {  this.name = name; } public Date getDate() {  return date; } public void setDate(Date date) {  this.date = date; } public Integer getMoney() {  return money; } public void setMoney(Integer money) {  this.money = money; } public Integer getDvalue() {  return dvalue; } public void setDvalue(Integer dvalue) {  this.dvalue = dvalue; } public Integer getMvalue() {  return mvalue; } public void setMvalue(Integer mvalue) {  this.mvalue = mvalue; } public Group getGroup() {  return group; } public void setGroup(Group group) {  this.group = group; } public Integer getGid() {  return gid; } public void setGid(Integer gid) {  this.gid = gid; } }[color=#FF0000]Things.hbm.xml[/color]__________________________________________________<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC  "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping> <class name="com.lg.bean.Things" table="lg_things">  <id name="id" type="java.lang.Integer" column="id">   <generator class="increment"></generator>  </id>  <property name="name" type="java.lang.String" length="50" column="name" />  <property name="date" type="java.util.Date" column="date" />  <property name="money" type="java.lang.Integer" column="money" />  <property name="dvalue" type="java.lang.Integer" column="dvalue" />  <property name="mvalue" type="java.lang.Integer" column="mvalue" />  <property name="gid" type="java.lang.Integer" column="gid" insert="false" update="false" />  <many-to-one name="group" class="com.lg.bean.Group" fetch="select">   <column name="gid" not-null="true" />  </many-to-one> </class> </hibernate-mapping>[color=#FF0000]ThingsDao.java[/color]_____________________________________________________________package com.lg.dao;import java.util.List;import com.lg.bean.Things;public interface ThingsDao { /**  * 保存一条记录  */ public void save(Things thing) ; /**  * 更新一条记录  */ public void update(Things thing) ; /**  * 删除一条记录  */ public void delete(Integer id) ; /**  * 查询单条记录  */ public Things find(Integer id) ; /**  * 查询所有记录  */ public List<Things> findAll() ; /**  * 按条件查询记录  */ public List<Things> pointFind(Object[] obj) ;}[color=#FF0000]ThingsDaoImpl.java[/color]_________________________________________________________package com.lg.dao.impl;import java.util.List;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.lg.bean.Things;import com.lg.dao.ThingsDao;public class ThingsDaoImpl extends HibernateDaoSupport implements ThingsDao { public void delete(Integer id) {  this.getHibernateTemplate().delete(this.find(id)) ; } public Things find(Integer id) {  return (Things) this.getHibernateTemplate().get(Things.class, id); } @SuppressWarnings("unchecked") public List<Things> findAll() {  String hql = "from Things things order by things.date" ;  List<Things> list = this.getHibernateTemplate().find(hql) ;  return list; } @SuppressWarnings("unchecked") public List<Things> pointFind(Object[] obj) {  String tj = "" ;  for(int i = 0 ; i<obj.length ; i++){   tj += "and".toString()+obj[i].toString()+"=".toString()+obj[i+1] ;   i++ ;  }  String hql = "from Things things where 0=0"+tj ;  List<Things> list = this.getHibernateTemplate().find(hql) ;  return list; } public void save(Things things) {  this.getHibernateTemplate().save(things) ; } public void update(Things things) {  this.getHibernateTemplate().update(things) ; }}[color=#FF0000]ThingsService.java[/color]____________________________________________________________package com.lg.service;import java.util.List;import com.lg.bean.Things;public interface ThingsService { /**  * 保存一条记录  */ public void save(Things thing) ; /**  * 更新一条记录  */ public void update(Things thing) ; /**  * 删除一条记录  */ public void delete(Integer id) ; /**  * 查询单条记录  */ public Things find(Integer id) ; /**  * 查询所有记录  */ public List<Things> findAll() ; /**  * 按条件查询记录  */ public List<Things> pointFind(Object[] obj) ;}ThingsServiceImpl.java________________________________________________________package com.lg.service.impl;import java.util.List;import com.lg.bean.Things;import com.lg.dao.ThingsDao;import com.lg.service.ThingsService;public class ThingsServiceImpl implements ThingsService { private ThingsDao thingsDao ; public void setThingsDao(ThingsDao thingsDao) {  this.thingsDao = thingsDao; } public void delete(Integer id) {  thingsDao.delete(id) ; } public Things find(Integer id) {  return thingsDao.find(id); } public List<Things> findAll() {  return thingsDao.findAll(); } public List<Things> pointFind(Object[] obj) {  return thingsDao.pointFind(obj); } public void save(Things thing) {  thingsDao.save(thing) ; } public void update(Things thing) {  thingsDao.update(thing) ; }}[color=#FF0000]ThingsAction.java[/color]_________________________________________________________package com.lg.action;import java.util.Map;import com.lg.bean.Group;import com.lg.bean.Things;import com.lg.service.GroupService;import com.lg.service.ThingsService;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;@SuppressWarnings("serial")public class ThingsAction extends ActionSupport { private Things things ; private Group group ; private ThingsService thingsService ; private GroupService groupService ; public void setThings(Things things) {  System.out.println("in setThings");  this.things = things; } public Things getThings() {  System.out.println("in getThings");  return things; } public void setThingsService(ThingsService thingsService) {  this.thingsService = thingsService; }  public Group getGroup() {  return group; } public void setGroup(Group group) {  this.group = group; } public void setGroupService(GroupService groupService) {  this.groupService = groupService; } @Override public String execute() throws Exception {  // TODO Auto-generated method stub  return SUCCESS; } public String save(){  System.out.println(things.getName());  System.out.println(things.getDate());  System.out.println(things.getMoney());  System.out.println(things.getMoney());  System.out.println(things.getGid());  System.out.println(things.getDvalue());  thingsService.save(things) ;  return SUCCESS ; } @SuppressWarnings("unchecked") public String forsave(){  Map request = (Map)ActionContext.getContext().get("request") ;  request.put("glist", groupService.getList()) ;  return SUCCESS ; }  public String update(){  thingsService.update(things) ;  return SUCCESS ; }  @SuppressWarnings("unchecked") public String findAll(){  Map request = (Map)ActionContext.getContext().get("request") ;  request.put("list", thingsService.findAll()) ;  return SUCCESS ; }  @SuppressWarnings("unchecked") public String find(){  Map request = (Map)ActionContext.getContext().get("request") ;  request.put("list", thingsService.find(things.getId())) ;  return SUCCESS ; }  public String delete(){  thingsService.delete(things.getId()) ;  return SUCCESS ; } }[color=#FF0000]UserValidateInterceptor.java[/color]________________________________________________________package com.lg.interceptor;import java.util.Map;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;@SuppressWarnings("serial")public class UserValidateInterceptor extends AbstractInterceptor { @SuppressWarnings("unchecked") public String intercept(ActionInvocation ai) throws Exception {  Map session = ai.getInvocationContext().getSession() ;  String result = null ;  if(null!=session.get("user")){   result = ai.invoke() ;  }else{   result = Action.LOGIN ;  }  return result; }}[color=#FF0000]DateFormate.java[/color]_________________________________________________________package com.lg.utils;import java.util.Date;public class DateFormate { public static Date getDate(){  return new java.sql.Date((new Date()).getYear(),(new Date()).getMonth(),(new Date()).getDay()) ; }}[color=#FF0000]struts.xml[/color]_______________________________________________________<?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> <package name="lvg" extends="struts-default">   <interceptors>   <interceptor name="userValidateInterceptor" class="com.lg.interceptor.UserValidateInterceptor" />  </interceptors>    <global-results>   <result name="login" type="redirect">/index.jsp</result>  </global-results>  <!-- User 相关的action -->  <action name="register" class="register">   <result name="success" type="redirect">/index.jsp</result>   <result name="input">/register.jsp</result>  </action>  <action name="login" class="login">   <result name="success" type="redirect">/main.jsp</result>   <result name="input">/index.jsp</result>  </action>    <!-- Group 相关的action -->  <action name="grouplist" class="group" method="getList">   <result name="success">/grouplist.jsp</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="deleteGroup" class="group" method="delete">   <result name="success" type="redirect">grouplist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="updateGroup" class="group" method="getOne">   <result name="success">/update.jsp</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="update" class="group" method="update">   <result name="success" type="redirect">grouplist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="saveGroup" class="group" method="save">   <result name="success" type="redirect">grouplist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>    <!-- Things 相关的action -->  <action name="thingslist" class="things" method="findAll">   <result name="success">/thingslist.jsp</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="forsave" class="things" method="forsave">   <result name="success">/record.jsp</result>   <result name="input">thingslist.action</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="savethings" class="things" method="save">   <result name="success" type="redirect">thingslist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="forupdatethings" class="things" method="find">   <result name="success">/update.jsp</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="updatethings" class="things" method="update">   <result name="success" type="redirect">thingslist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="deletethings" class="things" method="delete">   <result name="success" type="redirect">thingslist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>  <action name="detail" class="things" method="delete">   <result name="success" type="redirect">thingslist.action</result>   <result name="input">/main.jsp</result>      <interceptor-ref name="userValidateInterceptor" />   <interceptor-ref name="defaultStack" />  </action>   </package></struts>[color=#FF0000]applicationContext.xml[/color]_________________________________________________________-<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>  <property name="url" value="jdbc:mysql://localhost:3306/lg_data"></property>  <property name="username" value="root"></property>  <property name="password" value="root"></property>  <property name="maxActive" value="100"></property><!-- 最大活动连接数 -->  <property name="maxIdle" value="30"></property><!-- 最大可空闲的连接数 -->  <property name="maxWait" value="500"></property><!-- 最大可以等待的连接数 -->  <property name="defaultAutoCommit" value="true"></property><!-- 默认自动提交,true每执行完一次数据操作之后就自动提交,相当于没有事物--> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource" ref="dataSource"></property>  <property name="hibernateProperties">   <props>    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>    <prop key="hibernate.show_sql">true</prop>   </props>  </property>  <property name="mappingResources">   <list>    <value>com/lg/bean/User.hbm.xml</value>    <value>com/lg/bean/Group.hbm.xml</value>    <value>com/lg/bean/Things.hbm.xml</value>   </list>  </property> </bean> <!-- User 相关的bean --> <bean id="userDao" class="com.lg.dao.impl.UserDaoImpl" scope="prototype">  <property name="sessionFactory">   <ref bean="sessionFactory"/>  </property> </bean> <bean id="userService" class="com.lg.service.impl.UserServiceImpl" scope="prototype">  <property name="userDao" ref="userDao"></property> </bean>  <bean id="register" class="com.lg.action.RegisterAction" scope="prototype">  <property name="userService" ref="userService"></property> </bean>  <bean id="login" class="com.lg.action.LoginAction" scope="prototype">  <property name="userService" ref="userService"></property> </bean> <!-- Group 相关的bean --> <bean id="groupDao" class="com.lg.dao.impl.GroupDaoImpl" scope="prototype">  <property name="sessionFactory">   <ref bean="sessionFactory"/>  </property> </bean> <bean id="groupService" class="com.lg.service.impl.GroupServiceImpl" scope="prototype">  <property name="groupDao" ref="groupDao"></property> </bean> <bean id="group" class="com.lg.action.GroupAction" scope="prototype">  <property name="groupService" ref="groupService"></property> </bean> <!-- Things 相关的bean --> <bean id="thingsDao" class="com.lg.dao.impl.ThingsDaoImpl" scope="prototype">  <property name="sessionFactory">   <ref bean="sessionFactory" />  </property> </bean> <bean id="thingsService" class="com.lg.service.impl.ThingsServiceImpl" scope="prototype">  <property name="thingsDao" ref="thingsDao" /> </bean> <bean id="things" class="com.lg.action.ThingsAction" scope="prototype">  <property name="thingsService" ref="thingsService" />  <property name="groupService" ref="groupService" /> </bean></beans>[color=#FF0000]record.jsp[/color]____________________________________________________________<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib prefix="lg" uri="/struts-tags"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <title>V1.0</title>    <link rel="stylesheet" type="text/css" href="style/class.css">  </head>    <body>   <lg:label value="%{getText('add.things')}" cssClass="title"></lg:label>    <lg:form action="savethings" method="post">     <lg:hidden name="things.mvalue" value="1"></lg:hidden>     <lg:textfield name="things.name" label="%{getText('name.things')}" id="name" cssClass="text"></lg:textfield>     <lg:textfield name="things.date" label="%{getText('date.things')}" id="date" cssClass="text"></lg:textfield>     <lg:textfield name="things.money" label="%{getText('money.things')}" id="money" cssClass="text"></lg:textfield>     <lg:select list="#{'0':'没用','1':'拿不定','2':'有用'}" label="%{getText('dayvalue.things')}" name="things.dvalue" cssClass="text" id="dvalue" />     <lg:select list="#request.glist" listKey="gid" listValue="gname" label="%{getText('groupname')}" name="things.gid" cssClass="text" id="gid"></lg:select>     <lg:submit value="::%{getText('submit')}::" name="submit"></lg:submit>    </lg:form>  </body></html> 希望大家多帮忙看看,小弟先谢过了…… 问题补充:<div class="quote_title">lizhi92574 写道</div><div class="quote_div"><br />没发现问题你是不是还少给了东西,struts.xml 不止这一个文件吧。<br /><br />都没看到<br /><pre name="code" class="java">&lt;constant name="struts.objectFactory" value="spring" /&gt;</pre></div><br />似乎跟这个没有关系,因为其他dao.service,action都用的这个struts,那个objectFactory似乎在他默认的struts-default文件里边有,如果拿出来只不过是对他进行覆盖,跟这个似乎没有直接关系……

解决方案

action中定义的private Things things ; private Group group ;修改为private Things things =new Things (); private Group group =new Group ();要不然获取时会抛出异常的。
解决方案二:
默认不是spring,web.xml 配置发来看看。
解决方案三:
没发现问题你是不是还少给了东西,struts.xml 不止这一个文件吧。都没看到<constant name="struts.objectFactory" value="spring" />

时间: 2024-09-10 09:06:18

s2sh中struts2的页面的值无法传的action中,相当头痛……的相关文章

jquery中如何在页面加载的时候根据action中的值的长度动态生成div

问题描述 jquery中如何在页面加载的时候根据action中的值的长度动态生成div 我action中的数据是保存在json中,然后要根据数据记录数生成多个div, //门店信息信息加载 $.ajax({ url:"findAllStoreInfoAction.action?workDate="+showCurrentTime(), dataType:"json", type:"POST", async:false, success: func

一个页面可以得到两个不同action中的不同session.setAttribute(里面的值)吗

问题描述 如题一个页面可以得到两个不同action中的不同session.setAttribute(里面的值)吗现在的那个页面只可以得到其中一个action中的session,另一个却得不到是不是strut-xml里面要配点啥啊? 问题补充:xiaofancn 写道 解决方案 要想获取Session的值,给Session赋值的方法先执行.,能否贴出你的代码解决方案二:你的页面是怎么跳转的?解决方案三:<s:iterator value="#session.msg"> <

隐藏-将jsp页面上的信息传递到action中

问题描述 将jsp页面上的信息传递到action中 各位大神,求帮忙!!! 页面上的信息是这样: <table class="tabmenu" <c:if test="${fn:length(tabmap) < 2}">style="display:none"</c:if>> <tr> <c:forEach var="tab" items="${tabmap

如何将鼠标点中的listbox项的值赋给同一个界面中的一个textbox

问题描述 如何将鼠标点中的listbox项的值赋给同一个界面中的一个textbox C#2008,access2003在同一个界面中,listbox已经连接数据库,listbox中各项也能正确显示.如何将鼠标点中的listbox项的值赋给同一个界面中的一个textbox,使textbox中的值能够正确显示是汉字,代码该如何写?listbox和textbox不在同一个界面代码又该如何写?求助!感谢! 解决方案 listbox的selectchange事件可以捕获当前选中项把 不同一个界面是什么意思

javaee-struts.xml 中package 的 namespace 的值自动加到链接中了

问题描述 struts.xml 中package 的 namespace 的值自动加到链接中了 struts.xml中定义了一个包 name="user" extends="struts-default" namespace="/users" 定义了一个action名为user,成后返回页面的路径如下WEB-INF/content/users/success.jsp 在浏览器地址栏输入:http://localhost:8081/multiMod

link中如何根据checkbox的值在多个属性中模糊查询?

问题描述 link中如何根据checkbox的值在多个属性中模糊查询? link中如何根据checkbox的值在多个属性中模糊查询? 解决方案 参考: http://blog.csdn.net/q107770540/article/details/5724013 public void Test(string a, string b, string c,string d) { QueryContext query = new QueryContext(); var q = from u in q

oracle-如何将A表中的字段一的值赋值给B表中的字段一

问题描述 如何将A表中的字段一的值赋值给B表中的字段一 这是我编写的的 UPDATE poc.zjqx p SET (p.as_of_date) = ( SELECT (o.as_of_date) FROM poc.scqx o WHERE p.as_of_date = o.as_of_date 可是没有通过,该怎么搞,求指教 解决方案 oracle 如何将一个表的某个字段赋值给另一张表的某个字段将A表中某个字段的值赋给B表某个字段SQl 将A表中的字段Name的值更新到B表中 解决方案二: u

Struts2 中&amp;amp;lt;s:iterator&amp;amp;gt;标签取Action中List值的问题

问题描述 这是sql查询出来的格式:adname |showPrice|clickPrice|clicktimes|showtimes| date |advertid海马有声小说| 10 | 0.1 |21 | 100 |2010-10-23| 7 我希望通过我在Action中执行一条SQL语句,把其值赋给一个list.并且通过request.setAttribute("adlist", list);把值存入到request中.在页面使用Struts2的<s:iterator v

Struts2中的数据处理的三种方式对比(Action中三种作用域request,session,application对象)

1:在Action中如何获得作用域(request,session,application)对象: 取得Map(键值对映射集)类型的requet,session,application; 对数据操作的所有方法:(即把数据保存到域中) 主要使用的是方式2和方式3: 方式1:直接获取ServletApi,核心类是ServletActionContext提供的静态的方法; 1 package com.bie.lesson04; 2 3 import javax.servlet.ServletConte