SSH开发输出少内容,发现是插入数据的问题,看看问题在哪儿?

最近学习了浪曦风中叶张老师的SSH项目,自己做的时候发现输出少内容,控制台没有报错,结果如下:
List User
序号 姓名 密码 年龄 更新 删除
1 e update delete
开始把User的name属性是username的时候,姓名有输出,密码和年龄没有输出,年龄显示为0(那时候age的类型为int)。
发现先在数据库中输入数据可以得到结果,就是在jsp页面输入数据到数据库的过程中有问题,名字和年龄在数据库中均为空。
请高手看看是哪儿的问题,谢谢!

下面为主要代码:

index.jsp
[code="java"]


SaveUser/s:a

ListUser/s:a
[/code]

save.jsp(内容部分国际化)
[code="java"]
/s:textfield
/s:textfield
/s:textfield
/s:submit
/s:form[/code]

list.jsp
[code="java"]









      <s:iterator value="#request.list" id="us">
          <tr>
              <td><s:property value="#us.id"/></td>
              <td><s:property value="#us.name"/></td>
              <td><s:property value="#us.password"/></td>
              <td><s:property value="#us.age"/></td>
              <td><s:a href="updatePUser.action?user.id=%{#us.id}">update</s:a></td>
              <td><s:a href="deleteUser.action?user.id=%{#us.id}">delete</s:a></td>
          </tr>
      </s:iterator>

序号 姓名 密码 年龄 更新 删除
[/code]

User.java
[code="java"]package cn.lz.bean;

public class User {

private Integer id;
private String name;
private String password;
private Integer age;

public User() {}

public User(String name, String password, Integer age) {
    this.name = name;
    this.password = password;
    this.age = age;
}

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 String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public Integer getAge() {
    return age;
}

public void setAge(Integer age) {
    this.age = age;
}

}[/code]

User.hbm.xml
[code="java"]<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<class name="User" table="user">
    <id name="id" type="java.lang.Integer" column="id">
        <generator class="increment"/>
    </id>
    <property name="name" type="string" column="name"/>
    <property name="password" type="string" column="password"/>
    <property name="age" type="java.lang.Integer" column="age"/>
</class>


[/code]

UserDAO.java UserDAOImpl.java
[code="java"]package cn.lz.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.lz.bean.User;
import cn.lz.dao.UserDAO;

public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {

@SuppressWarnings("unchecked")
public List<User> getAllUsers() {
    return this.getHibernateTemplate().find("from User user order by user.id desc");
}

public User getUserById(Integer id) {
    return (User) this.getHibernateTemplate().get(User.class, id);
}

public void removeUser(User user) {
    this.getHibernateTemplate().delete(user);
}

public void saveUser(User user) {
    this.getHibernateTemplate().save(user);
}

public void updateUser(User user) {
    this.getHibernateTemplate().update(user);
}

}[/code]

UserService.java UserServiceImpl.java
[code="java"]package cn.lz.service.impl;

import java.util.List;

import cn.lz.bean.User;
import cn.lz.dao.UserDAO;
import cn.lz.service.UserService;

public class UserServiceImpl implements UserService {

private UserDAO userDAO;

public void setUserDAO(UserDAO userDAO) {
    this.userDAO = userDAO;
}

public void delete(User user) {
    this.userDAO.removeUser(user);
}

public List<User> getAll() {
    return this.userDAO.getAllUsers();
}

public User getById(Integer id) {
    return this.userDAO.getUserById(id);
}

public void save(User user) {
    this.userDAO.saveUser(user);
}

public void update(User user) {
    this.userDAO.updateUser(user);
}

}
[/code]

struts.xml
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">




listUser.action
/save.jsp

    <action name="listUser" class="listUserAction">
        <result name="success">/list.jsp</result>
    </action>
</package>

[/code]

applicationContext.xml
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
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/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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="jdbc:mysql://localhost:3306/test"/>
    <property name="username" value="root"/>
    <property name="password" value="lz"/>
    <!-- 连接池启动时的初始值 -->
    <property name="initialSize" value="1"/>
    <!-- 连接池的最大值 -->
    <property name="maxActive" value="100"/>
    <!-- 最大空闲值.经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
    <property name="maxIdle" value="30"/>
    <!-- 最小空闲值.当空闲的连接数少于阈值时,连接池就会去预申请一些连接,以免洪峰来时来不及申请 -->
    <property name="minIdle" value="1"/>
</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>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>cn/lz/bean/User.hbm.xml</value>
        </list>
    </property>
</bean>

<bean id="userDAO" class="cn.lz.dao.impl.UserDAOImpl">
    <property name="sessionFactory">
        <ref bean="sessionFactory"/>
    </property>
</bean>

<bean id="userService" class="cn.lz.service.impl.UserServiceImpl">
    <property name="userDAO" ref="userDAO"></property>
</bean>

<bean id="saveUserAction" class="cn.lz.action.user.SaveUserAction" scope="prototype">
    <property name="service" ref="userService"></property>
</bean>

<bean id="listUserAction" class="cn.lz.action.user.ListUserAction" scope="prototype">
    <property name="service" ref="userService"></property>
</bean>

[/code]

web.xml
[code="java"]<?xml version="1.0" encoding="UTF-8"?>
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<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>

<context-param>
    <param-name>contextConfigLocation </param-name>
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>

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


[/code]

1个回答

saveUserAction能获得jsp传上来的数据不?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问