ReadAction public class ReadAction extends Action {
   public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
                        ***其中怎么写***
                        过程怎么请详细
                     }
            }==================================================================================
ReadFormpackage struts.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class ReadForm extends ActionForm {
private String content;
    private String time;
    private String email;
    private String item;
    private String name;
    private String url;
    public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

return null;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {

} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getUrl() {
return url;
} public void setUrl(String url) {
this.url = url;
}
}
===================================================================================
jsp页面怎么写??可以把数据库中的数据显示出来
我知道虽然这样直接问有点过火,但是我实在是没有办法了,那位路过的大侠,帮帮忙

解决方案 »

  1.   

    觉得应该先连接SqlServer , 然后 写 SQL 语句  ,返回一个 LIST ,  再在页面进行迭代,就可以了!
      

  2.   

    这个过程我知道,但是就是sql和jsp的代码不会写
      

  3.   

    DAO 类 public List getUserByName(String userName) { List list = new ArrayList(); String sql = "select * from UserInfo where name =?"; con = ConnectionManager.getCn();
    try {
    ps = con.prepareStatement(sql);
    ps.setString(1, userName);
    rs = ps.executeQuery(); while (rs.next()) {
    LoginInfo loginInfo = new LoginInfo();
    loginInfo.setId(rs.getInt("id"));
    loginInfo.setName(rs.getString("name"));
    loginInfo.setPwd(rs.getString("pwd"));
    list.add(loginInfo);
    } } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    try { ConnectionManager.closeRs(rs);
    ConnectionManager.closePs(ps);
    ConnectionManager.closeCn(con); } catch (SQLException e) {
    e.printStackTrace();
    } } return list; }Action 类 /**
     * 登录方法
     */
    public ActionForward login(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) { LoginForm checkform = (LoginForm) form;
    UserInfoService userInfoService = new UserInfoService();
    LoginInfo loginInfo = new LoginInfo();
    loginInfo = checkform.getLoginInfo(); boolean bool = userInfoService.Login(loginInfo); if (bool) {
    request.setAttribute("loginInfo", loginInfo);
    return new ActionForward("/ok.jsp");
    } else { return new ActionForward("/Error.jsp");
    }
    }
      

  4.   

    我没有用DAO类,就直接用的Action 、Form 和Jsp 。登录我可以登录的,就是无法从数据库将数据读取出来!
      

  5.   

     DAO代码 从数据库取数据的      
    //通过用户名获取该用户的充值记录条数
    public int getAllLogNumByCn(String cn)throws Exception{
    Criteria criteria = getCriteria();
    if(cn!=null)
    criteria.add(Expression.eq("cn", cn));
    criteria.setProjection(Projections.rowCount());
    return ((Number)criteria.uniqueResult()).intValue();
    } //通过用户名获取该用户的充值记录信息
    @SuppressWarnings("unchecked")
    public List getAllByCn(String cn) throws Exception{
    Criteria criteria = getCriteria();
    if(cn!=null)criteria.add(Expression.eq("cn", cn)); return criteria.list();
    }
    //共用的方法
    private Criteria getCriteria(){
    return this.getSession(true).createCriteria(RechargeLog.class);//RechargeLog为实体 与 数据库 表对应部分action 代码
    List allLogs = null;
    int allCounts = 0;
    int allpage = 0; try {
    allLogs = mems.getAllByCn(cn);
    allCounts = mems.getAllLogNumByCn(cn);
    request.setAttribute("allLogs", allLogs);                  request.setAttribute("allCounts", allCounts); return mapping.findForward("query_ok");
    } catch (RuntimeException e) {
    return mapping.findForward("error");
    }
    }
    在Action;里面存 然后去 JSP页面取数据JSP页面 int allCounts = (Integer) request.getAttribute("allCounts");
    List allLogs = (List) request.getAttribute("allLogs");显示:
    <table width="903" height="182" border="0">
    <tr>
    <td height="37" colspan="8">
    <div align="center"></div>
    <div align="center">
    <B><FONT size=6> <bean:message key="rechargeLog.title"/></FONT> </B>
    </div>
    </td>
    </tr>
    <tr>
    <td width="139" height="39">
    <div align="center" class="STYLE4">
    <bean:message key="user.recharge.cn"/>
    </div>
      </td>
    <td width="99">
    <div align="center" class="STYLE4">
    <bean:message key="user.recharge.cardid"/>
    </div>
      </td>
    <td width="126">
    <div align="center" class="STYLE4">
    <bean:message key="rechargeLog.date"/>
    </div>
      </td>
    <td width="122">
    <div align="center" class="STYLE4">
    <bean:message key="rechargeLog.ip"/>
    </div>
      </td>
    <td width="109">
    <div align="center" class="STYLE4">
    <bean:message key="rechargeLog.point"/>
    </div>
      </td>
    <td width="91">
    <div align="center" class="STYLE4">
    <div align="center">
    <bean:message key="rechargeLog.presentPoint"/>
    </div>
    </div>
      </td>
      <td width="91">
    <div align="center" class="STYLE4">
    <div align="center">
    <bean:message key="rechargeLog.jxsName"/>
    </div>
    </div>
      </td>
    </tr>

    <%
    EsalseDealerInfo jxsInfo = null;
    String jxsrealName = null;

    for(int i=0;i<allLogs.size();i++){
    RechargeLog log = (RechargeLog)allLogs.get(i);

    String cn = log.getCn();
    Long cardNo = log.getCardNo();

    String cardNos = cardNo+"";
    String cardN1 = cardNos.substring(0,4);
    String cardN2 = cardNos.substring(8,10);

    Date date = log.getChargeDate();
    String ip = log.getIp();
    Double point = log.getPoint();
    Double p_point = log.getPresentPoint();

    Long jxsId = log.getDealerId();
    if(jxsId!=0){
    jxsInfo = (EsalseDealerInfo)jxss.load(jxsId);
    jxsrealName = jxsInfo.getRealName();
    }else{
    jxsrealName = "";
    }
     %>
    <tr>
    <td height="36">
    <div align="center">
    <%=cn %>
    </div>
    </td>
    <td>
    <div align="center">
    <%=cardN1 %>****<%=cardN2 %>
    </div>
    </td>
    <td>
    <div align="center">
    <fmt:formatDate value="<%=date %>"/>
    </div>
    </td>
    <td>
    <div align="center">
    <%=ip %>
    </div>
    </td>
    <td>
    <div align="center">
    <%=point %>
    </div>
    </td>
    <td>
    <div align="center">
    <%=p_point %>
    </div>
    </td>
    <td>
    <div align="center">
    <%=jxsrealName %>
    </div>
    </td>
    </tr>
    <%
    }
     %>
    <tr>
    <td colspan="6">
    <center>
     <f:fenye className="doUser" para="opers" functionName="getAll" pageNum="<%=pageNum%>" totalPage="<%=allpage %>" /></center>
    </td> </tr>
    </table>当然这里你也可以用 foreach 循环
      

  6.   

    使用hibernate从数据库中读取数据一定要用DAO吗??能否在Action中实现这个功能,从而在jsp页面中显示呢?
      

  7.   

    execute方法:
    首先构造你的业务逻辑类
    比如:Services s=new Services();
         List<XXX> list=s.getXXXAll();//这就是一个从业务逻辑类中查询数据内容。至于
          request.setAttribute("list",list);
         reutnr mapping.findForward("showList");//知道和配置文件的对应关系吧?页面:
     <table>
     <c:forEach item="${list}" var="item">
      <tr><td>
       ${item.属性}
       </td>
      </tr>
    </table>
    至于getXXXAll();内容是什么就是hibernate简单的读取操作。
      

  8.   

     ReadAction类,想用ReadAction从Mess表中读取信息,Mess表中有id,name,url,item,email,content,time.几个列
     
    public class ReadAction extends Action {
       public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    Session session=HibernateSessionFactory.getSession();
    Query q=session.createQuery("from Mess");
    List list=q.list();
    request.setAttribute("display.list", list);
    HibernateSessionFactory.closeSession();
    return mapping.findForward("display");
    }
    }display.jsp页面<%@ page language="java" pageEncoding="utf-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>留言本</title>
    <link rel="stylesheet" type="text/css" href="css/css.css">
    </head><body>
    <p><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber3">
      <tr>
        <td width="140" valign="top" align=center> 
          
        </td> 
        <td><img border="0" src="images/guestbook.jpg"><p style="margin: 0 20"> 
        </td>  
      </tr>  
    </table>   <c:forEach items="${requestScope['display.list']}" var="article">  
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber3">  
      <tr>  
        <td width="140" valign="top">  
        </td>  
        <td>  
        <br>  
        <div align="center">  
          <center>  
          <table  style="word-break:break-all" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#3F8805" width="90%" id="AutoNumber4">  
            <tr>  
              <td height="20" bgcolor="#eefee0" width="75%">&nbsp;<img src="images/gb-index2.gif" align="absmiddle""> <c:out value="${name}"/> <font color="#3F8805"><c:out value="${time}"/>说</font>&nbsp;   <c:out value="${item}"/></td>  
              <td height="20" bgcolor="#eefee0" width="25%">  
              <p align="right" style="margin-right: 10">  
              <a href=mailto:<c:out value="${email}"/>><img border='0' alt='信箱 <c:out value="${email}"/>' src=images/gb-mail.gif align='absmiddle'></a>&nbsp;
      <a href="<c:out value="${url}"/>">
      <img border='0'  src=images/gb-url.gif align='absmiddle'>  
      </a>  
      </td>  
            </tr>  
            <tr>  
              <td colspan="2" height="120" style="WORD-WRAP: break-word">  
                <p style="line-height: 140%; margin-left: 15; margin-right: 10; margin-top: 10; margin-bottom: 5" align=left><c:out value="${content}"/>
      
        </p>  
    </td>  
            </tr>  
            </table>  
          </center>  
    </div> </td> </tr> </table>   
      </c:forEach> 
      
      
      
      
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber5">  
      <tr>   
        <td width="140" valign="top"> </td>  
        <td> <br> <div align="center">   
            <center>  
              <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#3F8805" width="90%" id="AutoNumber6">  
                <tr>   
                  <td colspan="2" height="50">&nbsp;    
                  </td>  
                </tr>  
              </table>  
            </center>  
          </div></td>  
      </tr>  
    </table>  </body></html>jsp页面中无法显示数据,想问一下错在哪里,怎么改,最好能说清楚点,谢谢啦!
      

  9.   

    ReadAction中定义一个list ,sql server 2000 从取得包装好的数据,放到list就行了,<s:iterator value="#request.list" status="userForm1">
         <s:property value="name"/><br/>
     </s:iterator>