Skip to content

Commit df9cdd1

Browse files
jerryJSP
1 parent 4b03dd7 commit df9cdd1

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

ScientificCalculator.jsp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<meta charset="UTF-8">
7+
<title>Scientific Calculator</title>
8+
</head>
9+
<body>
10+
Calculator<br><br>
11+
<form action="ScientificCalculator.jsp">
12+
<input type="text" name="num" value="0">Enter Number
13+
<input type="submit" value="sin()" name="op">
14+
<input type="submit" value="cos()" name="op">
15+
<input type="submit" value="tan()" name="op">
16+
<input type="submit" value="log()" name="op">
17+
<input type="submit" value="()^1/2" name="op">
18+
</form>
19+
<%
20+
try{int n = Integer.parseInt(request.getParameter("num"));
21+
String op = request.getParameter("op");
22+
if(op.equals("sin()"))
23+
out.print(Math.sin(n));
24+
if(op.equals("cos()"))
25+
out.print(Math.cos(n));
26+
if(op.equals("tan()"))
27+
out.print(Math.tan(n));
28+
if(op.equals("log()"))
29+
out.print(Math.log(n));
30+
if(op.equals("()^1/2"))
31+
out.print(Math.sqrt(n));}catch(Exception e){}
32+
%>
33+
</body>
34+
</html>

ServletBC.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
3+
import java.io.IOException;
4+
import java.sql.*;
5+
import javax.servlet.ServletException;
6+
import javax.servlet.annotation.WebServlet;
7+
import javax.servlet.http.HttpServlet;
8+
import javax.servlet.http.HttpServletRequest;
9+
import javax.servlet.http.HttpServletResponse;
10+
11+
/**
12+
* Servlet implementation class ServletBC
13+
*/
14+
@WebServlet("/ServletBC")
15+
public class ServletBC extends HttpServlet {
16+
private static final long serialVersionUID = 1L;
17+
18+
/**
19+
* @see HttpServlet#HttpServlet()
20+
*/
21+
public ServletBC() {
22+
super();
23+
// TODO Auto-generated constructor stub
24+
}
25+
26+
/**
27+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
28+
*/
29+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30+
// TODO Auto-generated method stub
31+
try {
32+
33+
Class.forName("com.mysql.jdbc.Driver");
34+
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stud", "root", "");
35+
Statement stmt = con.createStatement();
36+
ResultSet rs = stmt.executeQuery("SELECT * FROM STUDENT WHERE USN='"+request.getParameter("usn")+"'");
37+
while(rs.next()) {
38+
System.out.println(rs.getInt(1) + " " + rs.getString(2));
39+
}
40+
41+
} catch (Exception e) {
42+
// TODO: handle exception
43+
}
44+
}
45+
46+
}

UsnQuery.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Insert title here</title>
6+
</head>
7+
<body>
8+
<h3>USN QUERY</h3>
9+
<form action="ServletBC" method="GET">
10+
<input type="text" name="usn">
11+
<input type="submit" value="QUERY">
12+
</form>
13+
</body>
14+
</html>

VisitHome.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Visitor Count</title>
6+
</head>
7+
<body>
8+
<h1>VISIT COUNT</h1>
9+
<form action="VisitorCount" method="GET">
10+
UN <input type="text" name="us"><br><br>
11+
PW <input type="text" name="pw"><br><br>
12+
<input type="submit" value="GO">
13+
</form>
14+
</body>
15+
</html>

VisitorCount.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.IOException;
2+
import java.io.PrintWriter;
3+
4+
import javax.servlet.ServletException;
5+
import javax.servlet.annotation.WebServlet;
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
@WebServlet("/VisitorCount")
11+
public class VisitorCount extends HttpServlet {
12+
private static final long serialVersionUID = 1L;
13+
14+
public VisitorCount() {
15+
super();
16+
}
17+
18+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
19+
try {
20+
PrintWriter p = response.getWriter();
21+
response.setContentType("text/html");
22+
String un = request.getParameter("us");
23+
String pw = request.getParameter("pw");
24+
if(un.equals("ash") && pw.equals("123")) {
25+
p.println("SUCCSEESESE");
26+
}
27+
else {
28+
p.print("LOGIN SFAil");
29+
}
30+
} catch(Exception e) {}
31+
}
32+
}

web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
3-
<display-name>JerryLets</display-name>
3+
<display-name>jerry_jsp</display-name>
44
<welcome-file-list>
55
<welcome-file>index.html</welcome-file>
66
<welcome-file>index.htm</welcome-file>

0 commit comments

Comments
 (0)