我用了框架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总是显示不了数据。怎么回事。请各位帮我想想办法呀。
谢谢各位了。

解决方案 »

  1.   

     <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>
    这样试试
      

  2.   

    在Action中有user这个对象吗?而且这个对象要有getter和setter方法,且User类中要有:userId、userId、userId的getter和setter方法。
      

  3.   

    <input type="text" name="user.userId">
    麻烦你把name的引号去掉,否则数据传不到后台
      

  4.   

    你先确保你的list有值且已经传到页面。
      

  5.   


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

  6.   

    Map request = (Map)ActionContext.getContext().get("request");
    list = this.service.findAll();
    System.out.println(list.size()+"="+list.size());[b][/b]
    你先看看你的list.size()是否输出为空?
    不为空的话,可能是页面上有问题!
      

  7.   

    <form action="action" method="post">
      <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>
    这样写 看看
      

  8.   

    补充下 private List<User> list = new ArrayList<User>();
      

  9.   

    你的list都有setter getter方法了还request.put("list", list)干什么。
      

  10.   

    这么写
    <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也不行啊!各位能不能帮我出出招呀!谢谢各位了呀
      

  11.   

    你在页面上:
    <s:property value="list.size"/>看看list传到页面么?
      

  12.   

    <s:property value="list.size"/>好像在页面上面没有显示。难道传值不对。还是……帮帮看看吧。谢谢呀
      

  13.   

    在action中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);
    不行吗?各位能不能帮我看看,是我这么写有问题。还是……帮我看看吧。谢谢你们了呀
      

  14.   

    要不你帮我看看吧。我刚刚学struts2还不怎么会用呀。帮帮忙吧
      

  15.   

    这么简单的问题,用Debug跟踪到Action里,看list有没有值啊,如果有值,需要确保list有get、set方法,再用以上方法就可现实记录数据了。
      

  16.   

    liuyunhua0066,你能不能帮我看看。大家能不能帮我想想办法呀。这个问题怎么解决呀!谢谢各位了呀
      

  17.   

    我们上班不准上QQ。QQ多屏蔽了。你就这样告诉我吧。谢谢
      

  18.   

    list = this.service.findAll();
    System.out.println(list.size()+"="+list.size());打印出来的是多少?
      

  19.   

    login()这个方法你用源码的形式贴出来。还有你的struts的配置文件。
      

  20.   

    DEBUG一下 看看 点定在RETURN SUCCESS 那 看看 LIST 有数据没,还有 看看 STRUTS的配置文件 是否 配置页面ACTION指定到这个类的这个方法里了
      

  21.   

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

  22.   

    com.test.action.user 
    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>
      

  23.   

    com.test.dao
    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>
    我全部把代码贴出来了。你帮我仔细看看吧。谢谢呀
      

  24.   


    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是多少?
      

  25.   

    页面的<s:property value="list.size"/>
    有值么?
      

  26.   

    代码写的应该没有问题。struts.xml中怎么配置要想在jsp显示结果,action中result配置必须是以下形式:
    <result>页面</result>

    <result type="dispatcher">页面</result>
      

  27.   

    result 的type默认的就是dispatcher。
      

  28.   

    因为你的DAO是这样: 
    String hql = "from User user order by user.userId desc";
      

  29.   

    问你一下type默认的就是dispatcher是什么意思。谢谢
      

  30.   

      Dispatcher结果类型是最常用的结果类型,也是struts2框架默认的结果类型。这个结果类型有个location参数,他是一个默认的参数。因为他是默认参数,你也可以像下面的一样使用param元素把一个值传递给他:
        <result name=".....">
           <param name="location">resource</param>
        </result>
        也可以直接把那个值传递给result元素:
        <result name=".....">resource</result>
        这个结果类型将把控制权转交给同一个应用程序里的某个资源,这个资源通常是某个JSP页面后者HTML文件。你不能利用它将控制权转交给一个外部资源,他的location参数不能被赋值一个绝对路径的URL地址。如果需要把控制权转交给一个外部资源,你应该选用Redirect结果类型
      

  31.   

    还有就是。我显示数据时,不是每一条数据都有id,id大的显示在上面,id小的显示在下面。怎么回事呢?谢谢
      

  32.   

    你都不看回复么?这个已经在50楼给你说过了。
    因为你用的是DESC。
      

  33.   

    其实问题很容易解决,建议楼主自己多测测,尝试各种问题分析排除,当你解决了问题之后你会很有成就感,对能力提高很有帮助。
    在项目部署运行正常的情况下:
    1.如果页面没有数据,后太没有异常,那么打印看看是否真的取到数据,或者是否数据条目是0条。
    2.如果有数据,看看是不是没有设置request的属性,request,setAttribute("key","value").
    3.如果设置了reuqest属性用于输出,那么就是在页面输出的语句有问题,使用了struts、spring标签还是EL表达式还是直接的jsp脚本,根据情况检查。到此,你应该可以发现问题的原因了。
      

  34.   

    private UserService service = new UserSerive();
      

  35.   

    private UserService service = new UserService();
      

  36.   

    ---------------------《宣传内容一》--------------------标题:3000元/月急聘网络兼职打字员(适合在校学生兼职)中国新搜狐网络兼职是专业为国内外出版社、印刷企业与文章小说网站提供打字录入排版校对的专业外包公司,主要提供的业务有打字、排版、校对、信息维护。公司接受2000多家客户的文字外包业务,现向全国公开急聘网络兼职输入员1000名。要求会打字,工作认真仔细,不限学历和年龄。由于前期工作任务有一定难度,工资也相应较高,工资130元/万字,工资通过支付宝、银行转帐、办事处专员送达方式日结。
    职位名称:网络兼职打字员
    职位要求:会电脑打字,懂WORD软件,上网比较熟练。地区、年龄不限。
    职位性质:公司将小说手稿扫描后,EMAIL至员工邮箱或专人送达,员工完成WORD输入后发至公司 邮箱即可,适合在校学生。
    工作地点:家里、网吧均可工作。(能上网即可)
    职位待遇:130元/万字,工资每日结算。 
    职位介绍:主要工作是负责打字、资料入录,发布信息等,工作简单,但要求细心,有责任心,为人诚实。 
    申请加入请登录:www.job-sohu.com 网络兼职
    邮箱:[email protected]
    (绝不以任何理由收取押金,手续费,更不会拖欠工资)
      

  37.   

    在请问各位在struts2中从页面怎么传值到action。
    我自己写了个例子。页面的代码如下
           <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;这么接收行不呀!我急需解决。谢谢
      

  38.   

    你是使用extends ActionSupport,那么,你传进来的User Model,Struts会帮你new,然而对于UserService,Struts却不会帮你new,就需要你手动new,这就是我上面回复中,让你改为private UserService service = new UserService();的原因.而使用extends ActionSupport这种办法,你若想从页面传递参数进来,比如你说的想传进来userId,那么你就需要user.userId,因为你必须把model也传进来,这样的话,Struts就会帮你new。而user.userId的user,就是你action里面的User Model,所以你需要在action里面有一个private User user;,当然上面说的UserService,UserModel的service,user都必须有getter和setter,因为Struts需要.另外,若你是初学,我建议你使用ModelDriven这种方法使用Model,这样你更能深刻的体会到Struts的工作机理,也会更加了解MVC.