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

Struts+Hibernate的问题.....请高手来帮帮忙吧!
在根据ID去删除一条数据的时候 获取不到那个ID 打印时是空值
  是怎么回事啊



这是Action:
public class DeleteAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
UserDao udao = new UserDao();
String path = "";
int stadiumId = Integer.parseInt(request.getParameter("stadiumId"));
System.out.println(stadiumId);
udao.query(stadiumId);
path = "list";
return mapping.findForward(path);
}
}
这是DAO:
public void query(int StadiumId){
Session session = HibernateSessionFactory.getSession();
Transaction tran = session.beginTransaction();
String hsql = "delete form TbStadia t where t.stadiumId = :stadiumId";
Query query = session.createQuery(hsql)
.setInteger(0, StadiumId);
query.executeUpdate();
tran.commit();
HibernateSessionFactory.closeSession();
}
页面的:
<form action="user.do">
  <table>
  <tr>
  <td colspan="3"><input type="submit" value="查询"/></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>编号</td>
  <td colspan="2">名称</td>
  <td></td>
  </tr>
  <c:forEach items="${list}" var="list">
<tr>
<td>${list.stadiumId }</td>
<td>${list.name }</td>
<td><a href="delete.do">删除</a></td>
</tr>
  </c:forEach>
  </table>
  </form>


------解决方案--------------------
你的页面中form中应该有名字叫stadiumId的参数吧? 不然后台怎么request? 
没写过标签,不过应该这样吧,根据你的写法,应该是 delete.do?stadiumId=${list.stadiumId}吧?