我用到两个框架struts2和Hibernate.现在我要把学生的信息从数据库中取出,全部显示在display.jsp中
1'这是到层实现方法:我想问这个list中保存的是什么信息?
public List select(){
Session session =sessionfac.getSession();
Query query = session.createQuery("from Student");
List list = query.list();
session.close();
return list ;
}
2'在Struts2中的Action中该怎么写? 下面是我写的,不知道该怎么写了。
public String execute(){
List list =(List)studentDao.select();
Iterator it = list.iterator();
Student stu = new Student();
//while(it.next()){
// System.out.println(stu.getName());
}
return SUCCESS;
}
其实我的疑问就是怎么把取出来的值在jsp页面中显示出来,在网上查了下有用request.setAtrribute()的,
用struts2的标签该怎么做?各位大大,这个问题困扰我好久!现在处于学习上升期,不要让我打击到
1'这是到层实现方法:我想问这个list中保存的是什么信息?
public List select(){
Session session =sessionfac.getSession();
Query query = session.createQuery("from Student");
List list = query.list();
session.close();
return list ;
}
2'在Struts2中的Action中该怎么写? 下面是我写的,不知道该怎么写了。
public String execute(){
List list =(List)studentDao.select();
Iterator it = list.iterator();
Student stu = new Student();
//while(it.next()){
// System.out.println(stu.getName());
}
return SUCCESS;
}
其实我的疑问就是怎么把取出来的值在jsp页面中显示出来,在网上查了下有用request.setAtrribute()的,
用struts2的标签该怎么做?各位大大,这个问题困扰我好久!现在处于学习上升期,不要让我打击到
解决方案 »
- 问个获取自增长字段的问题。。
- applet能否异步运行?
- 关于runtime的一个难题,进来帮帮忙啊!在线等!!
- 关于javax.naming.NoInitialContextException:
- jsp中自定义错误页面问题请教?
- 请教:Win2000Server+JBuilder9+Tomcat5.0.16,如何部署项目?
- 如何得到一个字符串的ascci码,并把它转换成16进制数
- 询问:如何解决JSP连接SQL Server数据库所造成的进程不断增加?详细如下:
- 我还是不懂,请高手来个详细点的!感激之至
- 我可以请斑竹当老师吗?
- ssh中级联的表中记录怎么也删除不了
- ext 如何在文本框后加提示文字
package com.student.action;import java.util.Iterator;
import java.util.List;
import java.util.Map;import javax.servlet.http.HttpSession;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.student.Student;
import com.student.Dao.StudentDao;
import com.student.Dao.StudentDaoImpl;public class DisplayAction extends ActionSupport{
private Student student;
private List myList;
private StudentDao studentDao = new StudentDaoImpl();
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public List getMyList() {
return myList;
}
public void setMyList(List myList) {
this.myList = myList;
}
public String execute(){
List mylist =(List)studentDao.select();
this.setMyList(myList);
return SUCCESS;
}
display.jap改了
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head></head>
<s:head/>
<body>
<s:form action="DisplayAction">
<table>
<tr>
<td>id</td>
<td>姓名</td>
<td>性别</td>
<td>生日</td>
<td>学籍</td>
</tr>
<s:iterator value="mylist" status="st">
<tr>
<td><s:property value="#st.getId()"/></td>
<td><s:property value="#st.getName()"/></td>
<td><s:property value="#st.getSex()"/></td>
<td><s:property value="#st.getBirthday()"/></td>
<td><s:property value="#st.getNation()"/></td>
</tr>
</s:iterator>
</table>
<s:submit value="确定"/>
</s:form>
</body>
</html>
没结果啊????
<s:iterator value="mylist" status="st">
<tr>
<td> <s:property value="Id"/> </td>
<td> <s:property value="name"/> </td>
<td> <s:property value="sex"/> </td>
<td> <s:property value="..."/> </td>
<td> <s:property value="...."/> </td>
</tr>
</s:iterator>