-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.jsp
103 lines (81 loc) · 3.16 KB
/
search.jsp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<%@page import="java.util.*" %>
<%@page import="java.io.*" %>
<%@page import="java.sql.*" %>
<html>
<head>
<title>Search</title>
</head>
<style>
.page-container{
display:flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
</style>
<body>
<%
if(session==null){
response.sendRedirect("login.html");
}
String type = (String)session.getAttribute("type");
if(type==null){
RequestDispatcher rd= request.getRequestDispatcher("error.jsp");
request.setAttribute("error","sessionExpired");
rd.forward(request,response);
}
String search = request.getParameter("search"); // can be product id or name
if(search!=null){
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/pharma";
Connection con=DriverManager.getConnection(url,"root","root");
Statement st=con.createStatement();
String query= "select * from medicine where name='"+search+"' or product_id = '"+search+"'";
ResultSet rs= st.executeQuery(query);
if(rs.next()){
String name = rs.getString("name");
int id = rs.getInt("product_id");
int quantity= rs.getInt("quantity");
int price = rs.getInt("price");
if(quantity>0){
%>
<div class="card">
<h2><%= name %></h2>
<p>
Price: Rs. <%= price %> <br/>
Availablity: Available <br/>
</p>
<form action="addToCart.jsp" method="Post">
<input type="hidden" name="addCart" value="<%= id %>"/>
<input type="submit"name="submit" value="Add To Cart">
</form>
</div>
<%
} //iner if
else{
%>
<div class="card">
<h2><%= name %></h2>
<p>
Price: Rs. <%= price %> <br/>
Availablity: Not Available <br/>
</p>
</div>
<%
}// inner else
}// outer if
else{
%>
<span><h2 style="color:red;">No medicine found!</h2></span>
<%
}// outer else
st.close();
con.close();
}// end try block
catch(Exception e){ out.println(e);}
out.close();
}
%>
</body>
</html>