Skip to content
Permalink
Browse files
code final
  • Loading branch information
gajavillid committed Nov 22, 2022
0 parents commit 649aaaca75b10b1c584615809034f95ca1c23a22
Show file tree
Hide file tree
Showing 103 changed files with 4,546 additions and 0 deletions.
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
</properties>
</project-shared-configuration>
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.computingConsultaionService</groupId>
<artifactId>computingConsultaionService</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>computingConsultaionService</name>

<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,90 @@
package com.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.connection.DatabaseConnection;
import java.io.File;
import java.util.List;
import java.util.Random;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;


/**
*
* @author Dayasagar
*/
@WebServlet(name = "AddProduct", urlPatterns = {"/AddProduct"})
public class AddProduct extends HttpServlet {
private final String UPLOAD_DIRECTORY = "D:\\Web_API\\computingConsultaionService\\computingConsultaionService\\src\\main\\webapp\\uploads";

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session = request.getSession();
if (ServletFileUpload.isMultipartContent(request)) {
try {

FileItemFactory factory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload(factory);


List<FileItem> multiparts = upload.parseRequest(request);
System.out.println("QWERTYUI "+multiparts);
String imageName = null;
String itemName = null;
String itemQuantity = null;
String itemPrice = null;
String itemDescription = null;

String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder salt = new StringBuilder();
Random rnd = new Random();
while (salt.length() < 3) {
int index = (int) (rnd.nextFloat() * SALTCHARS.length());
salt.append(SALTCHARS.charAt(index));
}

for (FileItem item : multiparts) {
if (!item.isFormField()) {
imageName = new File(item.getName()).getName();
item.write(new File(UPLOAD_DIRECTORY + File.separator + imageName));
FileItem name = (FileItem) multiparts.get(0);
itemName = name.getString();
FileItem quantity = (FileItem) multiparts.get(1);
itemQuantity = quantity.getString();
FileItem price = (FileItem) multiparts.get(2);
itemPrice = price.getString();
FileItem description = (FileItem) multiparts.get(3);
itemDescription = description.getString();
}
}
try {

int id = 0;
String imagePath = UPLOAD_DIRECTORY;
int i = DatabaseConnection.insertUpdateFromSqlQuery("insert into products(id,name,price,quantity,description,image,image_path) values('" + id + "','" + itemName + "','" + itemPrice + "','" + itemQuantity + "','" + itemDescription + "','" + imageName + "','" + imagePath + "')");
if (i > 0) {
String success = "Product added successfully.";
session.setAttribute("message", success);
response.sendRedirect("pages/admin/postLogin/product/adminProductList.jsp");
}
} catch (IOException e) {
}
} catch (Exception ex) {
request.setAttribute("message", "Add item Failed due to " + ex);
}
} else {
request.setAttribute("message", "Unable to complete requests");
}
}
}
@@ -0,0 +1,58 @@
package com.admin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpSession;

import com.connection.DatabaseConnection;
import java.sql.SQLException;
/**
*
* @author Dayasagar
*/
@WebServlet(name = "AdminSignIn", urlPatterns= {"/AdminSignIn"})
public class AdminSignIn extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
//Getting all the parameters from the frontend (admin)
String email = request.getParameter("email");
String pass = request.getParameter("upass");
//Retriving our session
HttpSession hs = request.getSession();

//Calling Connection method
Connection con = DatabaseConnection.getConnection();

//Creating Statement
Statement st = con.createStatement();

//Querying inside the database
ResultSet resultset = st.executeQuery("select * from admin where email='" + email + "' AND password='" + pass + "'");
//If all the details are correct
if (resultset.next()) {
hs.setAttribute("uname", resultset.getString("name"));
//Redirecting admin to dashboard page
response.sendRedirect("pages/admin/postLogin/adminDashboard.jsp");

} else {
//If details are wrong
String message = "You have enter wrong credentials";
hs.setAttribute("credential", message);
//Redirecting admin to admin login page
response.sendRedirect("pages/admin/adminLogin.jsp");
}
} catch (IOException | SQLException e) {
System.out.println(e);
}
}

}
@@ -0,0 +1,44 @@
package com.admin;

import com.connection.DatabaseConnection;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
*
* @author Dayasagar
*/
@WebServlet(name = "EditProduct", urlPatterns = {"/EditProduct"})
public class EditProduct extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession session = request.getSession();
try {
String itemId = request.getParameter("id");
String itemName = request.getParameter("name");
String itemQuantity = request.getParameter("quantity");
String itemPrice = request.getParameter("price");
String itemDescription = request.getParameter("description");

try {
int i = DatabaseConnection.insertUpdateFromSqlQuery("update products set name='" + itemName + "',price='" + itemPrice + "',quantity='" + itemQuantity + "',description='" + itemDescription + "' where id='" + itemId + "'");
if (i > 0) {
String success = "Product editted successfully.";
session.setAttribute("message", success);
response.sendRedirect("pages/admin/postLogin/product/adminProductList.jsp");
}
} catch (IOException e) {
}
} catch (Exception ex) {
request.setAttribute("message", "Edit item Failed due to " + ex);
}
}

}
@@ -0,0 +1,70 @@
package com.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseConnection {

//Creating database Connection in java online shopping system
public static Connection connection;

//Creating universal method to open connect will mysql database
public static Connection getConnection() {
try {
//Registering with mysql Driver
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/computingconsltancyservices", "root", "7095");
} catch (Exception e) {
e.printStackTrace();
}
return (connection);
}

//Creating universal method to close connect will mysql database
public static void CloseConnection() {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}

//Creating universal method to query for retrieving information
public static ResultSet getResultFromSqlQuery(String SqlQueryString) {
//Creating Resultset object
ResultSet rs = null;
try {
//Checking whether the connection is null or null
if (connection == null) {
getConnection();
}
//Querying the query
rs = connection.createStatement().executeQuery(SqlQueryString);
} catch (Exception ex) {
ex.printStackTrace();
}
return rs;
}

//Creating universal method to query for inserting or updating information in mysql database
public static int insertUpdateFromSqlQuery(String SqlQueryString) {
int i = 2;
try {
//Checking whether the connection is null or null
if (connection == null) {
getConnection();
}
//Querying the query
i = connection.createStatement().executeUpdate(SqlQueryString);

} catch (Exception ex) {
ex.printStackTrace();
}
return i;
}
}

0 comments on commit 649aaac

Please sign in to comment.