Skip to content

Commit daef413

Browse files
Add files via upload
0 parents  commit daef413

46 files changed

Lines changed: 1523 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com</groupId>
8+
<artifactId>MyApp</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<name>MyApp Maven Webapp</name>
13+
<!-- FIXME change it to the project's website -->
14+
<url>http://www.example.com</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<maven.compiler.source>8</maven.compiler.source>
19+
<maven.compiler.target>8</maven.compiler.target>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<version>4.13.1</version>
27+
<scope>test</scope>
28+
</dependency>
29+
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
30+
<dependency>
31+
<groupId>com.mysql</groupId>
32+
<artifactId>mysql-connector-j</artifactId>
33+
<version>8.3.0</version>
34+
</dependency>
35+
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
36+
<dependency>
37+
<groupId>javax.servlet</groupId>
38+
<artifactId>javax.servlet-api</artifactId>
39+
<version>4.0.1</version>
40+
<scope>provided</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<finalName>MyApp</finalName>
46+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
47+
<plugins>
48+
<plugin>
49+
<artifactId>maven-clean-plugin</artifactId>
50+
<version>3.4.0</version>
51+
</plugin>
52+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
53+
<plugin>
54+
<artifactId>maven-resources-plugin</artifactId>
55+
<version>3.3.1</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>3.13.0</version>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-surefire-plugin</artifactId>
63+
<version>3.3.0</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-war-plugin</artifactId>
67+
<version>3.4.0</version>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-install-plugin</artifactId>
71+
<version>3.1.2</version>
72+
</plugin>
73+
<plugin>
74+
<artifactId>maven-deploy-plugin</artifactId>
75+
<version>3.1.2</version>
76+
</plugin>
77+
</plugins>
78+
</pluginManagement>
79+
</build>
80+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package controller;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.RequestDispatcher;
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
import dao.UsersDAO;
13+
import model.Student;
14+
15+
@WebServlet("/addRow")
16+
public class AddDataServlet extends HttpServlet{
17+
@Override
18+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
19+
int id=Integer.parseInt(req.getParameter("id"));
20+
String name=req.getParameter("name");
21+
double marks=Double.parseDouble(req.getParameter("marks"));
22+
long contact=Long.parseLong(req.getParameter("contact"));
23+
String gender=req.getParameter("gender");
24+
25+
Student s=new Student();
26+
s.setId(id);
27+
s.setName(name);
28+
s.setMarks(marks);
29+
s.setGender(gender);
30+
s.setContact(contact);
31+
32+
UsersDAO dao=new UsersDAO();
33+
34+
try {
35+
dao.addData(s);
36+
RequestDispatcher dispatcher =req.getRequestDispatcher("dashboard");
37+
dispatcher.forward(req, resp);
38+
} catch (Exception e) {
39+
e.printStackTrace();
40+
}
41+
}
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package controller;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.RequestDispatcher;
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
import dao.UsersDAO;
13+
14+
@WebServlet("/deleteData")
15+
public class DeleteServlet extends HttpServlet{
16+
@Override
17+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
18+
int id=Integer.parseInt(req.getParameter("id"));
19+
20+
UsersDAO dao=new UsersDAO();
21+
22+
try {
23+
if (dao.deleteRow(id)==0) {
24+
req.setAttribute("DeletedStatus", "Data Not Found");
25+
RequestDispatcher dispatcher= req.getRequestDispatcher("dashboard");
26+
dispatcher.forward(req, resp);
27+
}
28+
else {
29+
req.setAttribute("DeletedStatus", "Delete Successfully");
30+
RequestDispatcher dispatcher= req.getRequestDispatcher("dashboard");
31+
dispatcher.forward(req, resp);
32+
}
33+
} catch (Exception e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package controller;
2+
3+
import java.io.IOException;
4+
import java.sql.ResultSet;
5+
6+
import javax.servlet.RequestDispatcher;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.annotation.WebServlet;
9+
import javax.servlet.http.HttpServlet;
10+
import javax.servlet.http.HttpServletRequest;
11+
import javax.servlet.http.HttpServletResponse;
12+
13+
import dao.UsersDAO;
14+
15+
@WebServlet("/dashboard")
16+
public class DisplayAllServlet extends HttpServlet{
17+
@Override
18+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
19+
UsersDAO dao=new UsersDAO();
20+
ResultSet set;
21+
try {
22+
set = dao.DisplayAll();
23+
req.setAttribute("Display", set);
24+
RequestDispatcher dispatcher = req.getRequestDispatcher("dashboard.jsp");
25+
dispatcher.forward(req, resp);
26+
} catch (Exception e) {
27+
e.printStackTrace();
28+
}
29+
30+
}
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package controller;
2+
3+
import java.io.IOException;
4+
import java.io.PrintWriter;
5+
6+
import javax.servlet.RequestDispatcher;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.annotation.WebServlet;
9+
import javax.servlet.http.HttpServlet;
10+
import javax.servlet.http.HttpServletRequest;
11+
import javax.servlet.http.HttpServletResponse;
12+
import javax.servlet.http.HttpSession;
13+
14+
import dao.UsersDAO;
15+
import model.User;
16+
17+
18+
@WebServlet("/login")
19+
public class LoginServlet extends HttpServlet{
20+
private static final long serialVersionUID = 1L;
21+
22+
@Override
23+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
24+
String user=req.getParameter("username");
25+
String pass=req.getParameter("password");
26+
27+
UsersDAO dao =new UsersDAO();
28+
try {
29+
User u=dao.LoginAuthenticate();
30+
if (u.getUsername().equals(user)) {
31+
if (u.getPassword().equals(pass)) {
32+
HttpSession session= req.getSession(true);
33+
session.setAttribute("LoginSuccessful","Login Done" );
34+
RequestDispatcher dispatcher=req.getRequestDispatcher("dashboard");
35+
dispatcher.forward(req, resp);
36+
}
37+
else {
38+
req.setAttribute("LoginFailed", "Invalid Password");
39+
RequestDispatcher dispatcher=req.getRequestDispatcher("index.jsp");
40+
dispatcher.include(req, resp);
41+
}
42+
}
43+
else {
44+
req.setAttribute("LoginFailed", "Username Not Found");
45+
RequestDispatcher dispatcher=req.getRequestDispatcher("index.jsp");
46+
dispatcher.include(req, resp);
47+
}
48+
} catch (Exception e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
}

src/main/java/controller/Test.java

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dao;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
6+
public class DBConnection {
7+
private static final String Driver="com.mysql.cj.jdbc.Driver";
8+
private static final String url="jdbc:mysql://localhost:3306/billing_db";
9+
private static final String user="root";
10+
private static final String pass="root";
11+
12+
public static Connection getConnection() throws Exception {
13+
Class.forName(Driver);
14+
15+
return DriverManager.getConnection(url,user,pass);
16+
}
17+
}

src/main/java/dao/UsersDAO.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dao;
2+
3+
import java.sql.Connection;
4+
import java.sql.PreparedStatement;
5+
import java.sql.ResultSet;
6+
import java.sql.Statement;
7+
8+
9+
import model.Student;
10+
import model.User;
11+
12+
public class UsersDAO {
13+
14+
public User LoginAuthenticate() throws Exception {
15+
16+
Connection con = DBConnection.getConnection();
17+
18+
Statement s = con.createStatement();
19+
ResultSet rs = s.executeQuery("select * from user");
20+
User u = new User();
21+
22+
if (rs.next()) {
23+
u.setUsername(rs.getString("username"));
24+
u.setPassword(rs.getString("password"));
25+
}
26+
27+
return u;
28+
}
29+
30+
public ResultSet DisplayAll() throws Exception{
31+
Connection con = DBConnection.getConnection();
32+
33+
Statement s = con.createStatement();
34+
ResultSet rs = s.executeQuery("select * from Student");
35+
36+
return rs;
37+
}
38+
39+
public int addData(Student s)throws Exception {
40+
Connection con = DBConnection.getConnection();
41+
42+
PreparedStatement ps=con.prepareStatement("insert into student values(?,?,?,?,?)");
43+
ps.setInt(1, s.getId());
44+
ps.setString(2, s.getName());
45+
ps.setDouble(3, s.getMarks());
46+
ps.setLong(4, s.getContact());
47+
ps.setString(5, s.getGender());
48+
49+
return ps.executeUpdate();
50+
}
51+
52+
public int deleteRow(int id) throws Exception{
53+
Connection con = DBConnection.getConnection();
54+
55+
PreparedStatement ps=con.prepareStatement("delete from student where id = ?");
56+
ps.setInt(1, id);
57+
58+
return ps.executeUpdate();
59+
}
60+
}

src/main/java/model/Student.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package model;
2+
3+
public class Student {
4+
private int id;
5+
private String name;
6+
private double marks;
7+
private long contact;
8+
private String gender;
9+
10+
public int getId() {
11+
return id;
12+
}
13+
public void setId(int id) {
14+
this.id = id;
15+
}
16+
public String getName() {
17+
return name;
18+
}
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
public double getMarks() {
23+
return marks;
24+
}
25+
public void setMarks(double marks) {
26+
this.marks = marks;
27+
}
28+
public long getContact() {
29+
return contact;
30+
}
31+
public void setContact(long contact) {
32+
this.contact = contact;
33+
}
34+
public String getGender() {
35+
return gender;
36+
}
37+
public void setGender(String gender) {
38+
this.gender = gender;
39+
}
40+
}

src/main/java/model/User.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package model;
2+
3+
public class User {
4+
private String username;
5+
private String password;
6+
7+
8+
@Override
9+
public String toString() {
10+
return "User [username=" + username + ", password=" + password + "]";
11+
}
12+
public String getUsername() {
13+
return username;
14+
}
15+
public void setUsername(String username) {
16+
this.username = username;
17+
}
18+
public String getPassword() {
19+
return password;
20+
}
21+
public void setPassword(String password) {
22+
this.password = password;
23+
}
24+
25+
26+
}

0 commit comments

Comments
 (0)