struts-hibernate 从数据库中删除数据--初学
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DeleteForm deleteForm = (DeleteForm) form;// TODO Auto-generated method stub
int id=deleteForm.getId();
Session session=HibernateSessionFactory.getSession();
Transaction tr=session.beginTransaction();
User user=(User)session.get(User.class, new Integer(id));
session.delete(user);
tr.commit();
return mapping.findForward("success");
}
struts-config文件:
<action
attribute="deleteForm"
input="/delete.jsp"
name="deleteForm"
path="/delete"
scope="request"
type="com.sh.struts.DeleteAction">
<forward name="success" path="/success.jsp" />
</action>
delete.jsp文件:
<body>
<form action="/delete.do" method="get">
id : <input type="text" id="id" name="id"><br/>
<input type="submit" id="id" name="id" value="删除"><br/>
</form>
</body>
做删除操作:打开http://localhost:8080/struts_test/delete.jsp输入id=3
页面转到http://localhost:8080/delete.do?id=3&id=%C9%BE%B3%FD
提示:HTTP Status 400 - Invalid path /delete was requested