A Java web application built with Apache Tomcat, Java Servlets, JSP, and MySQL. This is a technology marketplace platform that supports user authentication with buyer and seller functionality.
Tech Barn is a web application that provides a platform for users to buy and sell consumer electronics. The application features user authentication, session management, and database integration with MySQL.
- Backend: Java Servlets (Java 8)
- Frontend: JSP (JavaServer Pages), HTML, CSS, JavaScript
- Database: MySQL
- Server: Apache Tomcat 9.0
- Build Tool: Maven
- JDBC Driver: MySQL Connector/J 5.1.49
final_proj_336/
βββ src/
β βββ main/
β βββ java/
β β βββ com/
β β βββ techbarn/
β β βββ webapp/
β β βββ ApplicationDB.java # Database connection handler
β β βββ HelloServlet.java # Hello servlet example
β β βββ LoginServlet.java # User authentication
β β βββ LogoutServlet.java # Session termination
β β βββ WelcomeServlet.java # Welcome page handler
β βββ resources/
β β βββ application.properties # Application configuration
β βββ webapp/
β βββ index.html # Landing page
β βββ login.jsp # Login page
β βββ logout.jsp # Logout page
β βββ welcome.jsp # Welcome page (after login)
β βββ static/
β β βββ css/
β β β βββ styles.css # Stylesheet
β β βββ js/
β β βββ app.js # Client-side JavaScript
β βββ WEB-INF/
β βββ web.xml # Web application configuration
β βββ lib/
β βββ mysql-connector-java-5.1.49-bin.jar
βββ sql/
β βββ schema.sql # Database schema
β βββ seed.sql # Sample data
βββ pom.xml # Maven configuration
βββ README.md # This file
Before you begin, ensure you have the following installed:
- Java Development Kit (JDK) 8 or higher
- Apache Tomcat 9.0 or compatible version
- MySQL 5.7+ or MySQL 8.0+
- Maven 3.6+
- Git (optional, for version control)
git clone <repository-url>
cd final_proj_336-
Create the MySQL database:
CREATE DATABASE tech_barn; USE tech_barn;
-
Run the schema file:
mysql -u root -p tech_barn < sql/schema.sql -
Seed the database (optional):
mysql -u root -p tech_barn < sql/seed.sql -
Update database credentials: Edit
src/main/java/com/techbarn/webapp/ApplicationDB.javaand update the connection details:String connectionUrl = "jdbc:mysql://localhost:3306/tech_barn" + "?useUnicode=true" + "&useSSL=false"; connection = DriverManager.getConnection(connectionUrl, "root", "your_password");
From the project root directory, run:
mvn clean installThis will compile the Java classes and create a WAR file in the target/ directory.
-
Copy the WAR file to Tomcat's
webappsdirectory:cp target/final_proj_336-1.0-SNAPSHOT.war $CATALINA_HOME/webapps/ -
Start Tomcat:
$CATALINA_HOME/bin/startup.sh # Linux/Mac # or $CATALINA_HOME/bin/startup.bat # Windows
- Configure Tomcat server in your IDE
- Add the project to the server
- Run the server from your IDE
Once Tomcat is running, access the application at:
- Home Page: http://localhost:8080/final_proj_336-1.0-SNAPSHOT/
- Login Page: http://localhost:8080/final_proj_336-1.0-SNAPSHOT/login
Note: The context path may vary depending on your deployment configuration.
The application is configured to connect to:
- Database:
tech_barn - Host:
localhost:3306 - Username:
root - Password:
password123
ApplicationDB.java before deploying to production!
- User Authentication: Login/logout functionality with session management
- Database Integration: MySQL database for user management
- Session Management: HTTP session handling for user state
- Servlet Architecture: RESTful servlet endpoints
- JSP Pages: Dynamic web pages with server-side rendering
Edit src/main/java/com/techbarn/webapp/ApplicationDB.java to modify:
- Database name
- Connection URL
- Username and password
The src/main/resources/application.properties file contains configuration settings (currently used as reference; actual database connection is handled in ApplicationDB.java).
The src/main/webapp/WEB-INF/web.xml file configures:
- Welcome files
- Servlet mappings
- Application metadata
The main user table includes:
user_id(Primary Key)usernamepwd(password)firstNamelastNameisBuyer(boolean)isSeller(boolean)dob(date of birth)addressemailphone_nopayment_infobank_accountrating
-
Test Database Connection:
java -cp "target/classes:src/main/webapp/WEB-INF/lib/mysql-connector-java-5.1.49-bin.jar" com.techbarn.webapp.ApplicationDB -
Test Login:
- Navigate to the login page
- Use credentials from
sql/seed.sqlor create a new user
-
Database Connection Failed
- Verify MySQL is running
- Check database credentials in
ApplicationDB.java - Ensure the database
tech_barnexists
-
ClassNotFoundException for MySQL Driver
- Verify
mysql-connector-java-5.1.49-bin.jaris inWEB-INF/lib/ - Check that the JAR is included in the WAR file
- Verify
-
404 Error on Pages
- Verify the context path matches your deployment
- Check
web.xmlconfiguration - Ensure JSP files are in the correct directory
-
Session Issues
- Clear browser cookies
- Check Tomcat session timeout settings
This project is licensed under the MIT License.
Final Project 336 - Database Systems Course
Note: This is a development/educational project. For production use, consider implementing:
- Password hashing (bcrypt, Argon2)
- SQL injection prevention (already using PreparedStatements - good!)
- HTTPS/SSL encryption
- Input validation and sanitization
- Error logging and monitoring
- Security headers and CSRF protection