-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRest3_Servlet.java
68 lines (56 loc) · 1.92 KB
/
Rest3_Servlet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package onlineFood;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.servlet.annotation.*;
/**
* Servlet implementation class Rest3_Servlet
*/
@WebServlet("/Rest3_Servlet")
public class Rest3_Servlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Rest3_Servlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name = String.valueOf(request.getParameter("chick"));
System.out.println(name);
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","123");
PreparedStatement ps =con.prepareStatement("select * from chicken where r_name=?");
ps.setString(1, name);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
String str = rs.getString(1);
int i = rs.getInt(2);
request.setAttribute("str", str);
request.setAttribute("i", i);
RequestDispatcher rd=request.getRequestDispatcher("YUMM.jsp");
rd.forward(request, response);
}
con.close();
ps.close();
}
catch (Exception e) {
System.out.println(e);
}
out.close();
}
}