我用了框架SSH2。但是登陆后跳转页面上无法显示记录。
reg.jsp是登陆界面
如下
<form action="saveUser.action" method="post">
<table align="center" width="40%" border="1">
<tr>
<td>
username
</td>
<td>
<input type="text" name="user.userId">
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<input type="password" name="user.userPwd">
</td>
</tr> <tr>
<td>
<input type="submit" value=" submit ">
</td>
<td>
<input type="reset" value=" reset ">
</td>
</tr> </form>
action如下
private static final long serialVersionUID = 1L;
private User user;
private List<User> list;
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
@SuppressWarnings("unchecked")
public String login() throws Exception
{
User u=null;
u=this.service.login(user.getUserId(),user.getUserPwd());
System.out.println("u ="+u);
if(u!=null){
Map request = (Map)ActionContext.getContext().get("request");
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());
if(list!=null){
request.put("list", list);
return SUCCESS;
}
}
return INPUT;
}
}regSuc.jsp如下
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<!--
<th>操作</th>
-->
</tr>
</thead> <tbody> <s:iterator id="mylist" value="#request.list" >
<tr align="center">
<td><s:property value="#mylist.userId"/></td>
<td><s:property value="#mylist.userName"/></td>
<td><s:property value="#mylist.userPwd"/></td>
<td><s:property value="#mylist.userSex"/></td>
<td><s:property value="#mylist.userAge"/></td>
<td><s:property value="#mylist.userFav"/></td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</s:iterator>
</tbody>
</table>但是跳转到页面regSuc.jsp总是显示不了数据。怎么回事。请各位帮我想想办法呀。
谢谢各位了。
reg.jsp是登陆界面
如下
<form action="saveUser.action" method="post">
<table align="center" width="40%" border="1">
<tr>
<td>
username
</td>
<td>
<input type="text" name="user.userId">
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<input type="password" name="user.userPwd">
</td>
</tr> <tr>
<td>
<input type="submit" value=" submit ">
</td>
<td>
<input type="reset" value=" reset ">
</td>
</tr> </form>
action如下
private static final long serialVersionUID = 1L;
private User user;
private List<User> list;
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
@SuppressWarnings("unchecked")
public String login() throws Exception
{
User u=null;
u=this.service.login(user.getUserId(),user.getUserPwd());
System.out.println("u ="+u);
if(u!=null){
Map request = (Map)ActionContext.getContext().get("request");
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());
if(list!=null){
request.put("list", list);
return SUCCESS;
}
}
return INPUT;
}
}regSuc.jsp如下
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<!--
<th>操作</th>
-->
</tr>
</thead> <tbody> <s:iterator id="mylist" value="#request.list" >
<tr align="center">
<td><s:property value="#mylist.userId"/></td>
<td><s:property value="#mylist.userName"/></td>
<td><s:property value="#mylist.userPwd"/></td>
<td><s:property value="#mylist.userSex"/></td>
<td><s:property value="#mylist.userAge"/></td>
<td><s:property value="#mylist.userFav"/></td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</s:iterator>
</tbody>
</table>但是跳转到页面regSuc.jsp总是显示不了数据。怎么回事。请各位帮我想想办法呀。
谢谢各位了。
解决方案 »
- struts2中文乱码,求解决方法
- The 'year' argument must be in range 1900 to 9999.
- win7下,java获取本地ip问题
- SSH整合 HTTP Status 404 - Servlet action is not available 错误
- 请推荐一本初学struts的书吧!谢谢
- 为什么下载总放在jsp页面里面呢?用java代码 在bean后台就出先问题,好像事解析了下载内容..
- 请高手帮忙,tomcat+mysql 数据库连接池配置的问题
- 请教一个不知道算不算简单的问题。急用,希望高手帮忙!!
- 怎么样保存登陆在线状态啊,用session不能随处访问,怎么办啊~~~~~~~~~急急急,help~~~~~~~
- 问一个Runtime.getRuntime().exec()的问题
- 求自定义异常类统一处理项目的全部异常方法
- struts2 默认的拦截器 上传下载
<tr align="center">
<td><s:property value="${mylist.userId}"/></td>
<td><s:property value="${mylist.userName}"/></td>
<td><s:property value="${mylist.userPwd}"/></td>
<td><s:property value="${mylist.userSex}"/></td>
<td><s:property value="${mylist.userAge}"/></td>
<td><s:property value="${mylist.userFav}"/></td>
这样试试
麻烦你把name的引号去掉,否则数据传不到后台
<td><s:property value="#mylist.userId"/></td>
<td><s:property value="#mylist.userName"/></td>
<td><s:property value="#mylist.userPwd"/></td>
<td><s:property value="#mylist.userSex"/></td>
<td><s:property value="#mylist.userAge"/></td>
<td><s:property value="#mylist.userFav"/></td>LZ这样的写法确实蛋疼。不妨看看1L的
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());[b][/b]
你先看看你的list.size()是否输出为空?
不为空的话,可能是页面上有问题!
<table align="center" width="40%" border="1">
<tr>
<td>
username
</td>
<td>
<s:textfield id="user.userId" name="user.userId" />
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<s:password id="user.userPwd" name="user.userPwd" /> </td>
</tr> <tr>
<td>
<input type="submit" value=" submit ">
</td>
<td>
<input type="reset" value=" reset ">
</td>
</tr> </form>
action如下
private static final long serialVersionUID = 1L;
private User user;
private List<User> list;public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}@SuppressWarnings("unchecked")
public String login() throws Exception
{
try{
//获取用户信息
User u=this.service.login(user.getUserId(),user.getUserPwd());
//添加到List中
list.add(u);
}catch(EXCEPTION e)
{
addActionError("error");//对应返回页面要有标签显示提示信息
return ERROR;
}
return SUCCESS;}regSuc.jsp如下
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<!--
<th>操作</th>
-->
</tr>
</thead> <tbody>
<s:iterator value="list" status="rowstatus">
<tr align="center">
<td><s:property value="userId"/></td>
<td><s:property value="userName"/></td>
<td><s:property value="userPwd"/></td>
<td><s:property value="userSex"/></td>
<td><s:property value="userAge"/></td>
<td><s:property value="userFav"/></td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</s:iterator>
</tbody>
</table>
这样写 看看
<s:iterator value="list" status="rowstatus">
<tr align="center">
<td><s:property value="userId"/></td>
<td><s:property value="userName"/></td>
<td><s:property value="userPwd"/></td>
<td><s:property value="userSex"/></td>
<td><s:property value="userAge"/></td>
<td><s:property value="userFav"/></td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</s:iterator也不行啊!各位能不能帮我出出招呀!谢谢各位了呀
<s:property value="list.size"/>看看list传到页面么?
Map request = (Map)ActionContext.getContext().get("request");
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());
if(list!=null){
request.put("list", list);
不行吗?各位能不能帮我看看,是我这么写有问题。还是……帮我看看吧。谢谢你们了呀
System.out.println(list.size()+"="+list.size());打印出来的是多少?
private User user;
private List<User> list;public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}@SuppressWarnings("unchecked")
public String login() throws Exception
{
User u=null;
u=this.service.login(user.getUserId(),user.getUserPwd());
System.out.println("u ="+u);
if(u!=null){
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());
if(list!=null){
return SUCCESS;}
}
return INPUT;
}}regSuc.jsp如下
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<!--
<th>操作</th>
-->
</tr>
</thead> <tbody> <c:forEach items="${list}" var="user">
<tr align="center">
<td>${user.userId}</td>
<td>${user.userName}td>
<td>${user.userPwd"}</td>
<td>${user.userSex"}</td>
<td><${user.userAge"}</td>
<td>${user.userFav"}</td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</c:forEach>
</tbody>
action的名称是 SaveUserAction.java 代码如下
public class SaveUserAction extends ActionSupport { /**
*
*/
private static final long serialVersionUID = 1L;
private User user;
private List<User> list;
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
@SuppressWarnings("unchecked")
public String login() throws Exception
{
User u=null;
u=this.service.login(user.getUserId(),user.getUserPwd());
System.out.println("u ="+u);
if(u!=null){
Map request = (Map)ActionContext.getContext().get("request");
list = this.service.findAll();
System.out.println(list.size()+"="+list.size());
if(list!=null){
System.out.println("list1="+list);
request.put("list", list);
return SUCCESS;
}
}
return INPUT;
}
}com.test.bean
实体Bean
名称 User.java 代码如下
public class User implements java.io.Serializable { // Fields private Integer userId;
private String userName;
private String userPwd;
private String userSex;
private int userAge;
private String userFav; // Constructors public String getUserSex() {
return userSex;
} public void setUserSex(String userSex) {
this.userSex = userSex;
} public int getUserAge() {
return userAge;
} public void setUserAge(int userAge) {
this.userAge = userAge;
} public String getUserFav() {
return userFav;
} public void setUserFav(String userFav) {
this.userFav = userFav;
} /** default constructor */
public User() {
} /** full constructor */
public User(Integer userId,String userName, String userPwd) {
this.userId=userId;
this.userName = userName;
this.userPwd = userPwd;
} // Property accessors public Integer getUserId() {
return this.userId;
} public void setUserId(Integer userId) {
this.userId = userId;
} public String getUserName() {
return this.userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getUserPwd() {
return this.userPwd;
} public void setUserPwd(String userPwd) {
this.userPwd = userPwd;
}
}
这个是实体的映射文件 User.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.test.bean.User" table="User" catalog="test">
<id name="userId" type="java.lang.Integer">
<column name="user_Id" />
<generator class="identity" />
</id>
<property name="userName" type="java.lang.String">
<column name="user_Name" length="20" />
</property>
<property name="userPwd" type="java.lang.String">
<column name="user_Pwd" length="20" />
</property>
<property name="userSex" type="java.lang.String">
<column name="user_Sex" length="20" />
</property>
<property name="userFav" type="java.lang.String">
<column name="user_Fav" length="20" />
</property>
<property name="userAge" type="java.lang.Integer">
<column name="user_Age" />
</property>
</class>
</hibernate-mapping>
DAO层 名称 UserDAO
public interface UserDAO {
public void saveUser(User user); public void removeUser(User user); public User findUserById(Integer id); public List<User> findAllUsers(); public void updateUser(User user); public User load(int id,String pass);
}
com.test.dao.impl
实现DAO的方法
public class UserDAOimpl extends HibernateDaoSupport implements UserDAO{
/*
* 获取所有数据
*/
@SuppressWarnings("unchecked")
public List<User> findAllUsers() {
String hql = "from User user order by user.userId desc";
return (List<User>) this.getHibernateTemplate().find(hql);
}
/*
* 获取指定的数据
*/
public User findUserById(Integer id) {
User user = (User) this.getHibernateTemplate().get(User.class, id);
return user;
}
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);
}
public User load(int id,String pass) {
User u=null;
HibernateTemplate ht=this.getHibernateTemplate();
u=(User)ht.get(User.class, id);
System.out.println(u.getUserPwd()+"1");
if(u!=null){
if(u.getUserPwd().equals(pass)){
return u;
}
}
return null;
}}
com.test.Service
Service层 UserService.java
public interface UserService {
public List<User> findAll();
public void save(User user);
public void delete(User user);
public User findById(Integer id);
public void update(User user);
public User login(int id,String pass);}com.test.Service.impl
实现Service层 UserServiceimpl
public class UserServiceimpl implements UserService{
private UserDAO userDao; public UserDAO getUserDao() {
return userDao;
}
public void setUserDao(UserDAO userDao) {
this.userDao = userDao;
}
//服务层的方法 public void delete(User user)
{
this.userDao.removeUser(user);
}
public List<User> findAll() {
return this.userDao.findAllUsers();
}
public User findById(Integer id) {
return this.userDao.findUserById(id);
}
public void save(User user)
{
this.userDao.saveUser(user);
}
public void update(User user)
{
this.userDao.updateUser(user);
}
public User login(int id,String pass) {
return this.userDao.load(id, pass);
} Spring配置文件 application.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:gate="http://gate.ac.uk/ns/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://gate.ac.uk/ns/spring http://gate.ac.uk/ns/spring.xsd
"> <!-- 以下使一些用到的类 在使用类中均没有实例化这个类,都交给了spring管理 -->
<!-- DAObean -->
<bean id="userDao" class="com.test.dao.impl.UserDAOimpl" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- DAObean -->
<bean id="userService" class="com.test.Service.impl.UserServiceimpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="saveUserAction" class="com.test.action.user.SaveUserAction">
<property name="service" ref="userService"></property>
</bean>
<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>
</beans>
hibernate的配置文件 hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration><session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://192.168.1.221:3306/test
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">
mysql_Paging
</property>
<property name="connection.username">tvlink</property>
<property name="connection.password">tvlink</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="show_sql">true</property>
<mapping resource="com/test/bean/User.hbm.xml" /></session-factory></hibernate-configuration>
struts2.xml配置文件<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="user" extends="struts-default">
<action name="saveUser" class="saveUserAction" method="login">
<result name="success" >/regSuc.jsp</result>
<result name="input">/regFail.jsp</result>
</action>
</package>
</struts>
登陆界面
reg.jsp 的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
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>SSH2用户注册</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<!--
<s:form action="saveUser" method="post">
<s:textfield name="user.userId" label="用名" ></s:textfield>
<s:textfield name="user.userPwd" label="密码" ></s:textfield>
<s:submit></s:submit>
</s:form>
-->
<!--
<s:fielderror></s:fielderror>
-->
<form action="saveUser.action" method="post">
<table align="center" width="40%" border="1">
<tr>
<td>
username
</td>
<td>
<input type="text" name=user.userId>
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<input type="password" name=user.userPwd>
</td>
</tr> <tr>
<td>
<input type="submit" value=" submit ">
</td>
<td>
<input type="reset" value=" reset ">
</td>
</tr> </form> </body>
</html>regSuc.jsp的代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<%
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>用户信息</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<!--
<th>操作</th>
-->
</tr>
</thead> <tbody>
<s:property value="list.size"/>
<s:iterator id="mylist" value="#request.list" >
<tr align="center">
<td><s:property value="#mylist.userId"/></td>
<td><s:property value="#mylist.userName"/></td>
<td><s:property value="#mylist.userPwd"/></td>
<td><s:property value="#mylist.userSex"/></td>
<td><s:property value="#mylist.userAge"/></td>
<td><s:property value="#mylist.userFav"/></td>
<td><a href="${crx}/delete.action?Id=${Id } ">删除</a></td>
<td><a href="${crx}/delete.action?Id=${Id } ">更新</a></td>
</tr>
</s:iterator>
</tbody>
</table>
</body>
</html>
regFail.jsp代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>注册失败</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
对不起注册失败 <br> </body>
</html>
我全部把代码贴出来了。你帮我仔细看看吧。谢谢呀
public String login() throws Exception {
User u = this.service.login(user.getUserId(), user.getUserPwd());
if (u != null) {
list = this.service.findAll();
System.out.println(list.size() + "=" + list.size());
if (list != null&&list.size()>0) {
return SUCCESS;
}
}
return INPUT;
}
你看看打印出来的size是多少?
有值么?
<result>页面</result>
或
<result type="dispatcher">页面</result>
String hql = "from User user order by user.userId desc";
<result name=".....">
<param name="location">resource</param>
</result>
也可以直接把那个值传递给result元素:
<result name=".....">resource</result>
这个结果类型将把控制权转交给同一个应用程序里的某个资源,这个资源通常是某个JSP页面后者HTML文件。你不能利用它将控制权转交给一个外部资源,他的location参数不能被赋值一个绝对路径的URL地址。如果需要把控制权转交给一个外部资源,你应该选用Redirect结果类型
因为你用的是DESC。
在项目部署运行正常的情况下:
1.如果页面没有数据,后太没有异常,那么打印看看是否真的取到数据,或者是否数据条目是0条。
2.如果有数据,看看是不是没有设置request的属性,request,setAttribute("key","value").
3.如果设置了reuqest属性用于输出,那么就是在页面输出的语句有问题,使用了struts、spring标签还是EL表达式还是直接的jsp脚本,根据情况检查。到此,你应该可以发现问题的原因了。
职位名称:网络兼职打字员
职位要求:会电脑打字,懂WORD软件,上网比较熟练。地区、年龄不限。
职位性质:公司将小说手稿扫描后,EMAIL至员工邮箱或专人送达,员工完成WORD输入后发至公司 邮箱即可,适合在校学生。
工作地点:家里、网吧均可工作。(能上网即可)
职位待遇:130元/万字,工资每日结算。
职位介绍:主要工作是负责打字、资料入录,发布信息等,工作简单,但要求细心,有责任心,为人诚实。
申请加入请登录:www.job-sohu.com 网络兼职
邮箱:[email protected]
(绝不以任何理由收取押金,手续费,更不会拖欠工资)
我自己写了个例子。页面的代码如下
<center> <font color="red">用户详细信息</font>
<table cellpadding="0" cellspacing="0" align="center" border="0" width="80%">
<thead>
<tr align="center">
<th>账号</th>
<th>姓名</th>
<th>口令</th>
<th>性别</th>
<th>年龄</th>
<th>爱好</th>
<th>操作</th>
</tr>
</thead> <tbody>
<s:iterator id="mylist" value="#request.list">
<tr align="center">
<td><s:property value="#mylist.userId"/></td>
<td><s:property value="#mylist.userName"/></td>
<td><s:property value="#mylist.userPwd"/></td>
<td><s:property value="#mylist.userSex"/></td>
<td><s:property value="#mylist.userAge"/></td>
<td><s:property value="#mylist.userFav"/></td>
<td>
<!--
<a href="update.jsp">修改</a>
-->
<a href='<s:url action="edit"><s:param name="userId" value="#mylist.userId"></s:param></s:url>'>修改</a>
<a href='<s:url action="delete"><s:param name="userId" value="userId"></s:param></s:url>'>删除</a>
<a href='<s:url action="insert"><s:param name="userId" value="userId"></s:param></s:url>'>添加</a>
</td>
</tr>
</s:iterator>
action中的代码如下
private static final long serialVersionUID = 1L;
private User user;
private List<User> list;
private String userId;
public List<User> getList() {
return list;
}
public void setList(List<User> list) {
this.list = list;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} private UserService service;
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
public String login() throws Exception
{
User u=null;
u=this.service.login(user.getUserId(),user.getUserPwd());
System.out.println("u ="+u);
if(u!=null){
Map request = (Map)ActionContext.getContext().get("request");
list = this.service.findAll();
if(list!=null){
request.put("list", list);
return SUCCESS;
}
}
return INPUT;
}
public String Add(){
User u=new User();
u.setUserId(Integer.parseInt(userId));
u.setUserName(user.getUserName());
u.setUserPwd(user.getUserPwd());
u.setUserSex(user.getUserSex());
u.setUserAge(user.getUserAge());
u.setUserFav(user.getUserFav());
this.service.save(u);
return SUCCESS;
}
public String update(){
User u=new User();
u.setUserId(user.getUserId());
u.setUserName(user.getUserName());
u.setUserPwd(user.getUserPwd());
u.setUserSex(user.getUserSex());
u.setUserAge(user.getUserAge());
u.setUserFav(user.getUserFav());
this.service.update(u);
return SUCCESS;
}
public String delete(){
User u=new User();
u.setUserId(Integer.parseInt(userId));
this.service.delete(u);
return SUCCESS;
}
public String loop(){
this.service.findAll();
return SUCCESS;
}
public String Edit(){
user=(User)this.service.edit(user.getUserId());
return SUCCESS;
}
}就是点击修改后,传过的值userId,我在action是这么接收的。private String userId;这么接收行不呀!我急需解决。谢谢