Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Servlet上调用DAO方法_Java_Hibernate_Jsp_Servlets_Dao - Fatal编程技术网

Java 在Servlet上调用DAO方法

Java 在Servlet上调用DAO方法,java,hibernate,jsp,servlets,dao,Java,Hibernate,Jsp,Servlets,Dao,我正在制作一个网页,用户可以通过rentID搜索租用的产品,在Servlet中,我想调用一个DAO方法,根据该rentID查找租用的产品,如果找到或没有租金,则将用户重定向到一个新网页 这是JSP,用户通过ID搜索产品 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org /TR/html4/loose.dtd"> <html> <head> &l

我正在制作一个网页,用户可以通过rentID搜索租用的产品,在Servlet中,我想调用一个DAO方法,根据该rentID查找租用的产品,如果找到或没有租金,则将用户重定向到一个新网页

这是JSP,用户通过ID搜索产品

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org   /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h3>Find Rent</h3><br>

<form  action="FindRent" method="GET">
<fieldset>
<p>
<label for="id">Rent ID</label>
<input type="text" name="id"/>
</p>
<p>
<input type="submit" value="Search" />
</p>
</fieldset>

</form>

</body>
</html>
这就是Servlet。如何调用该方法

public class FindRent extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public Rent find() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

嗯,创建RentHibernateDao对象,并调用适当的方法,根据需要返回HTML。
public class FindRent extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public Rent find() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int rentId= Integer.parseInt(request.getParameter("id"));       // capture the rent id
    RentDao dao= new RentHibernateDao();        // create the dao object
    dao.find(rentId);   // If successful, it returns you an object of Rent class
   // means Id is there
  // put your processing logic here
    request.getRequestDispatcher("desiredpage.jsp").forward(request, response);         // forward to your desired page

   }