Skip to content

Commit 0df6096

Browse files
committed
Initial commit
0 parents  commit 0df6096

34 files changed

+2593
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
.classpath
3+
.idea
4+
.project
5+
.settings/
6+
.vscode

Readme.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Java EE Servlet API
2+
3+
> A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed
4+
> by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly
5+
> used to extend the applications hosted by web servers. For such applications, Java Servlet technology defines HTTP-specific
6+
> servlet classes.
7+
>
8+
> The `javax.servlet` and `javax.servlet.http` packages provide interfaces and classes for writing servlets. All servlets
9+
> must implement the `Servlet` interface, which defines lifecycle methods. When implementing a generic service, you can
10+
> use or extend the `GenericServlet` class provided with the Java Servlet API. The `HttpServlet` class provides methods,
11+
> such as `doGet` and `doPost`, for handling HTTP-specific services.
12+
13+
[Oracle Servlet Tutorial](https://docs.oracle.com/javaee/7/tutorial/servlets001.htm)
14+
15+
## Project Description
16+
17+
This project builds a social media web application using JAVA EE Servlet API. It allows you to view friend's post and
18+
profile, add and update own post, update own profile, and chat with friends.
19+
20+
### Running the application
21+
22+
Requires Java 8 update 442 `1.8.0_442`
23+
24+
1. Clone this repository
25+
2. Use [`init_db.sql`](database/init_db.sql) script to seed a MySQL database running locally
26+
3. Add your database connection settings to `DBConnection.java`
27+
4. Run the application on Apache Tomcat server
28+
29+
### Screenshots
30+
31+
If everything is up and running properly, you should be able to use the following functionality:
32+
33+
#### Signup
34+
35+
<img src="docs/screenshots/signup.png" height=300>
36+
37+
#### Login
38+
39+
<img src="docs/screenshots/login.png" height=300>
40+
41+
#### Home
42+
43+
<img src="docs/screenshots/home.png" height=300>
44+
45+
#### Profile
46+
47+
<img src="docs/screenshots/profile.png" height=300>
48+
49+
#### Edit Profile
50+
51+
<img src="docs/screenshots/edit-profile.png" height=300>
52+
53+
#### New Post
54+
55+
<img src="docs/screenshots/update-post.png" height=300>
56+
57+
#### Friend List
58+
59+
<img src="docs/screenshots/friend-list.png" height=300>
60+
61+
#### Private Message
62+
63+
<img src="docs/screenshots/private-message.png" height=300>
64+
65+
#### Message List
66+
67+
<img src="docs/screenshots/message-list.png" height=300>

WebContent/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+

WebContent/WEB-INF/header.jsp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<%@ page import="dao.UserDAO"%>
2+
<header>
3+
<div class="fixed-top d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm ">
4+
<h3 class="my-0 mr-md-auto font-weight-normal">Social</h3>
5+
<nav class="my-2 my-md-0 mr-md-3">
6+
<a class="p-2 text-dark" href="${pageContext.request.contextPath}/home">Home</a> <a class="p-2 text-dark"
7+
href="${pageContext.request.contextPath}/profile">Profile</a> <a class="p-2 text-dark"
8+
href="${pageContext.request.contextPath}/message">Message</a>
9+
</nav>
10+
<div style="width: 110px; text-align: center;">
11+
<img style="border-radius: 100%; height: 60px; width: 60px;"
12+
src="<%= new UserDAO().getUserById((int) session.getAttribute("user_id")).getImage() %>" />
13+
</div>
14+
<div>
15+
<div class="row">
16+
<p style="text-align: center; width: 100%; margin-bottom: 2px;"><%= new UserDAO().getUserById((int) session.getAttribute("user_id")).getFirst_name() + " " + new UserDAO().getUserById((int) session.getAttribute("user_id")).getLast_name() %></p>
17+
<a style="width: 100%;" class="btn btn-outline-primary"
18+
href="${pageContext.request.contextPath}/logout">logout</a>
19+
</div>
20+
</div>
21+
22+
</div>
23+
</header>

WebContent/WEB-INF/home.jsp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8" %>
3+
<%@ page import="java.util.ArrayList"%>
4+
<%@ page import="model.Post"%>
5+
<%@ page import="dao.UserDAO"%>
6+
<%
7+
if (session == null || session.getAttribute("user_id") == null) {
8+
response.sendRedirect("login");
9+
}
10+
%>
11+
<!DOCTYPE html>
12+
<html>
13+
<head>
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1">
16+
<title>Home | Social</title>
17+
<link rel="shortcut icon" href="image/logo.png">
18+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
19+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
20+
<style type="text/css">
21+
.my-container {
22+
margin-top: 120px;
23+
}
24+
25+
@media (max-width:800px){
26+
.my-container {
27+
margin-top: 240px !important;
28+
}
29+
}
30+
</style>
31+
</head>
32+
<body class="bg-dark">
33+
34+
<%@include file="header.jsp" %>
35+
36+
<main role="main">
37+
<div class="my-container">
38+
<div class="row">
39+
<div class="col-md-4 col-sm-12">
40+
<div style="padding: 20px;">
41+
<form action="home" method="post">
42+
<div class="form-group">
43+
<label for="post" style="color: #ffffff">Create Post</label>
44+
<textarea name="post" class="form-control" id="post" rows="3"></textarea>
45+
</div>
46+
<button type="submit" class="btn btn-primary">Post</button>
47+
</form>
48+
</div>
49+
</div>
50+
<div class="col-md-8 col-sm-12">
51+
<div style="padding: 20px;">
52+
53+
<%
54+
ArrayList<Post> posts = (ArrayList<Post>) request.getAttribute("posts");
55+
56+
if(posts.size() == 0){
57+
%><h4 style="text-align: center; color: #ffffff;">No Posts.</h4><%
58+
}
59+
60+
for(int i=0; i<posts.size(); i++){
61+
%>
62+
63+
<div class="card mb-3">
64+
<div class="card-body">
65+
<div class="row">
66+
<div class="col-2">
67+
<img style="width: 100%; border-radius: 100%;" src="<%= new UserDAO().getUserById(posts.get(i).getUser_id()).getImage() %>" />
68+
</div>
69+
<div class="col-10">
70+
<h5 class="card-title">
71+
<%
72+
if(posts.get(i).getUser_id() == (int) session.getAttribute("user_id")){
73+
%><h5 class="card-title">me</h5><%
74+
} else{
75+
%>
76+
<h5 class="card-title"> <%= new UserDAO().getUserById(posts.get(i).getUser_id()).getFirst_name() %> </h5>
77+
<%
78+
}
79+
80+
%>
81+
</h5>
82+
<h6 class="card-subtitle mb-2 text-muted"><%= posts.get(i).getBody() %></h6>
83+
<p class="card-text"><%= posts.get(i).getPost_time() %></p>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
89+
<%
90+
}
91+
%>
92+
93+
</div>
94+
</div>
95+
</div>
96+
</div>
97+
</main>
98+
99+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
100+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
101+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
102+
<script src="https://cdn.ckeditor.com/4.11.4/standard/ckeditor.js"></script>
103+
<script>
104+
CKEDITOR.replace('post');
105+
</script>
106+
</body>
107+
</html>
528 KB
Binary file not shown.

0 commit comments

Comments
 (0)