日期:2014-05-20  浏览次数:20840 次

有关javaee的一个小问题,希望大家指导指导...帮帮看是什么错误,谢谢...
请教大家一问题,本程序当中报错的地方用红色标志出来了,不清楚到底是什么错误,请大家指教,谢谢...



<%@ page language="java" import="java.util.*" pageEncoding="gbk""%>
<%@ page import="java.io.File"%>
<%@ page import="hibernate_tier.Train"%>
<%@ page import ="org.hibernate.cfg.*"%>
<%@ page import ="org.hibernate.*" %>
<%@ page import ="hibernate_tier.HibernateUtil" %>



<%
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>paging</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>
  <body>
  <table>
  <tr>
  <td>列车车次</td>
  <td>始发地点</td>
  <td>始发时间</td>
  <td>终点站</td>
  <td>到达时间</td>
  <td>全程车票(元)</td>
  </tr>
  <%!
  Configuration cfg;
SessionFactory sf;
Session session;
Transaction tx;
Train t1=new Train();
//Query query;
%>
<%
//session =sf.openSession();
//session = HibernateUtil.currentSession();
//tx = session.beginTransaction();
%>
<%
try
{
/*File file = new File("C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\webapps\\Struts_Hibernate_first\\WEB-INF\\classes\\hibernate.cfg.xml");
cfg = new Configuration().configure(file);
sf = cfg.buildSessionFactory();
session = sf.openSession();
tx=session.beginTransaction();*/
session = HibernateUtil.currentSession();//报错Type mismatch: cannot convert from Session to HttpSession
tx=session.beginTransaction();//报错Multiple annotations found at this line:- The method beginTransaction() is undefined for the type HttpSession Query query = session.createQuery("from Train");//报错The method createQuery(String) is undefined for the type HttpSession //query = session.createQuery();
List list = query.list();
for(int i=0;i<list.size();i++)
{
Train t=(Train)list.get(i);
%>
<tr>
<td><%=new String(t.getTrainCode().getBytes("ISO8859_1")) %></td>
<td><%=new String(t.getStartStation().getBytes("ISO8859_1")) %> </td>
<td><%=t.getStartTime()%></td>
<td><%=t.getTerminal() %></td>
<td><%=t.getTerminalTime() %></td>
<td><%=t.getPrice()%></td>
<%
}
}catch(HibernateException e)
{
e.printStackTrace();
tx.rollback();
}
  %>
  </table>
  </body>
</html>


------解决方案--------------------
写一个测试类吧,先测试报错的地方是不是好使。。