jsp程序出错,求助(基于hibernate+Eclipse+MyEclipse)

<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%Stringpath=request.... <%@ 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">
<%@page import="cn.com.twm.*" %>
<%@page import="org.hibernate.*" %>

<!-- 导入需要的包 -->
<html>
<head>

<base href="<%=basePath%>">

<title>My JSP 'Ins.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
//判断id有没有值,如果有,则通过request对象获取多个请求参数
if (request.getParameter("id")!=null){
int id =Integer.parseInt(request.getParameter("id"));
String name =request.getParameter("name");
String department=request.getParameter("department");
Double salary=Double.parseDouble(request.getParameter("salary"));
try {
//根据用户请求信息构建一个持久化对象
Transaction tx=null;
Employee em=new Employee();
em.setId(id);
em.setName(name);
em.setDepartment(department);
em.setSalary(salary);
//打开一个hibernate会话
Session Hsession=HibernateUtil.currentSession();
tx=Hsession.beginTransaction;//调用session方法的save方法将持久化对象保存到数据库
Hsession.save(em);
tx.commit();
HibernateUtil.closeSession();
//关闭session
}catch(Exception e){
System.out.println("添加失败"+e);}
}
%>
<!--提交form表单元素 -->
<form action="Ins.jsp" method="post" name="forml" target="_self">
<p>ID:<input name="id" type="text" id="id">
</p>
<p>姓名:<input name="name" type="text" id="name">
</p>
<p>部门:<input name="department" type="text" id="department"></p>
<p>
薪水:<input name="salary" type="text" id="salary"></p>
<p> <input type="submit" name="submit" value="提交">
</p>

</form>

</body>
</html>

Severity and Description Path Resource Location Creation Time Id
提示错误原因:Hsession.beginTransaction cannot be resolved or is not a field hiber/WebRoot Ins.jsp line 48 1249807186375 62
还是不能运行
Ins.jsp这个页面可以填写表单,但是提交表单就出错,下面语句有问题
Session Hsession =HibernateUtil.currentSession();

org.apache.jasper.JasperException: An exception occurred processing JSP page /Ins.jsp at line 50

47: em.setDepartment(department);
48: em.setSalary(salary);
49: //镓揿紑涓�釜hibernate浼氲瘽
50: Session Hsession =HibernateUtil.currentSession();
51: tx =Hsession.beginTransaction();//璋幂敤session鏂规硶镄剆ave鏂规硶灏嗘寔涔呭寲瀵硅薄淇濆瓨鍒版暟鎹�簱
52: Hsession.save(em);
53: tx.commit();

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
展开
 我来答
shiryu963
2009-08-11 · 超过20用户采纳过TA的回答
知道答主
回答量:116
采纳率:0%
帮助的人:57.1万
展开全部
你的事务开启有问题
一般是这样写:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();
Transaction tx= session.beginTransaction();
session.save(user1);

tx.commit();
session.close();
sessionFactory.close();
qianthinkover
2009-08-10 · TA获得超过451个赞
知道小有建树答主
回答量:532
采纳率:0%
帮助的人:375万
展开全部
tx=Hsession.beginTransaction
Hsession他是什么没看见定义啊!

beginTransaction是方法吧!!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式