Java Hibernate查询数据显示在jsp页面

项目添加Struts2容器,使用标签s:iterator来遍历输出。

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>


  
    My JSP 'index.jsp' starting page
	
  
  
  
    This is my JSP page. 

display


    

struts.xml




	
			
				/index.jsp
			
	  

web.xml



  	
  
    index.jsp
  
  
  	struts2
  	
  		org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  	
  
  
  	struts2
  	/*
  

Home.java

package top.k10000;
import java.util.ArrayList;
import org.hibernate.Session;
import com.opensymphony.xwork2.ActionSupport;

public class Home extends ActionSupport{
	private static final long serialVersionUID = 1L;
	private ArrayList list;
	
	public ArrayList getList() {
		return list;
	}

	public void setList(ArrayList list) {
		this.list = list;
	}

	public Home(){
		Session session=HibernateSessionFactory.getSession();//通过HibernateSessionFactory类的getSession方法获得Session对象  
		ArrayList mylist=(ArrayList) session.createQuery("from User s").list();//执行HQL语句,查询内容,并转换为list集合
		this.list = mylist;
        for(int i=0;i

效果:

Java Hibernate查询数据显示在jsp页面_第1张图片


你可能感兴趣的:(Java)