Advance Java Project Workshop Guide
Advance Java Project Workshop Guide
Basic requirement
<%
User user=(User)[Link]("loggedinUSer");
boolean isloggedin=true;
if(user == null)
{
isloggedin=false;
[Link]("[Link]");
}
%>
<%
if(isloggedin)
{
%>
<li class="nav-item active"><a class="nav-link" href="logout">Logout
<span class="sr-only"></span>
</a></li>
<%
}else
{
%>
<%
}
%>
<%
if(isloggedin && [Link]().equalsIgnoreCase("admin"))
{
%>
<%
}
%>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search"
placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0"
type="submit">Search</button>
</form>
<%
if(isloggedin)
{
%>
<img src="pics/<%= user !=null?[Link]():"[Link]" %>"
alt=""
style="border-radius: 50%; margin-right: 5px; margin-left: 5px; border: 2px
solid black"
width="30" height="30"> <span><%= user!=null ?[Link]():"" %></span>
<%
}
%>
</div>
</nav>
<script src="[Link]
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script
src="[Link]
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script
src="[Link]
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
</head>
<body>
<!-- navbar -->
<jsp:include page="[Link]"></jsp:include>
<div class="row">
<%
List<Course> clist=null;
for(Course c:clist)
{
%>
<!-- course card column -->
</div>
</div>
</div>
}
%>
</div>
</div>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- navbar -->
<jsp:include page="[Link]"></jsp:include>
<div class="row">
<%
String loginmsg=(String)[Link]("loginmsg");
%>
<%
if(loginmsg!=null)
{
%>
<!-- alert message -->
<div class="alert alert-danger" role="alert">
<%= loginmsg %>
</div>
<%
}
%>
<%
String logoutmsg=(String)[Link]("logoutMessage");
%>
<%
if(logoutmsg!=null)
{
%>
<div class="alert alert-success" role="alert">
<%= logoutmsg %>
</div>
<%
}
%>
</div>
</div>
</div>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:include page="[Link]"></jsp:include>
<div class="row">
<div class="form-group">
<label for="lastinput">Last Name</label> <input type="text"
name="lname" class="form-control" id="lastinput"
aria-describedby="emailHelp" placeholder="Enter LastName">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label> <input
name="email" type="email" class="form-control"
id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="Enter email"> <small id="emailHelp"
class="form-text text-muted">We'll never share your email
with anyone else.</small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label> <input
name="pass" type="password" class="form-control"
id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<label for="mob">Mobile</label> <input type="number" name="mob"
class="form-control" id="mob" aria-describedby="emailHelp"
placeholder="Enter mobile No">
</div>
<div class="form-group">
<label for="exampleFormControlFile1">Upload profile pic</label> <input
name="pic" type="file" class="form-control-file"
id="exampleFormControlFile1">
</div>
</div>
</div>
</body>
</html>
[Link](assignment)
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- navbar -->
<jsp:include page="[Link]"></jsp:include>
<div class="container">
</div>
<p class="lead">Take it as assignment and complete View Feature</p>
</div>
</div>
</div>
</section>
<!-- Related items section-->
</div>
</body>
</html>
[Link]
<%@page import="[Link]"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
User user=(User)[Link]("loggedinUSer");
if(user==null)
{
[Link]("[Link]");
}else if([Link]().equalsIgnoreCase("admin"))
{
String cid=[Link]("cid");
int id=[Link](cid);
%>
<div class="container">
<div class="row">
<div class="form-group">
<label for="lastinput">Course Duration</label> <input value="<%= [Link]() %>"
type="text"
name="cdur" class="form-control" id="lastinput"
aria-describedby="emailHelp" placeholder="Enter Course Duration">
</div>
<div class="form-group">
<label for="lastinput">Course Description</label>
<textarea value="<%= [Link]() %>" name="cdesc" class="form-control" id="cdesc"
rows="3"><%= [Link]() %></textarea>
</div>
<div class="form-group">
<label for="lastinput">Course Fee</label>
<textarea value="<%= [Link]() %>" name="cfee" class="form-control" id="cdesc" rows="3"><%=
[Link]() %></textarea>
</div>
<div class="form-group">
<label for="exampleFormControlFile1">Upload Course Image</label> <input
name="cpic" type="file" class="form-control-file"
id="exampleFormControlFile1">
<span><%= [Link]() %></span>
</div>
<div class="form-group">
<label for="exampleFormControlFile1">Upload Course PDF</label> <input
name="cpdf" type="file" class="form-control-file"
id="exampleFormControlFile1">
<span><%= [Link]()%></span>
</div>
</div>
</div>
</div>
<%
}else
{
}
%>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<div class="row">
<%
User user=(User)[Link]("loggedinUSer");
if(user==null)
{
[Link]("[Link]");
}else if([Link]().equalsIgnoreCase("admin"))
{
List<Course> courseList=null;
for(Course c:courseList)
{
%>
<%
}
}
else
{
%>
<%
List<Course> courseList=null;
CourseService service=new CourseServiceImpl();
courseList=[Link]();
for(Course c:courseList)
{
%>
<%
}
}
%>
</div>
</div>
</body>
</html>
[Link]
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String del=(String)[Link]("del");
if(del!=null)
{
%>
<div class="alert alert-success" role="alert">
<%= del %>
</div>
<%
}
%>
<div class="container">
<div class="row">
<div class="col-12">
<h3>All Courses</h3>
<table class="table table-hover">
<thead>
<tr>
<%
if([Link]()!=0)
{
for(Course c:course)
{
int uid=[Link]();
UserService us=new UserServiceImpl();
String fname=[Link](uid);
%>
<tr>
</tr>
<%
}
%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
User user=(User)[Link]("loggedinUSer");
if(user ==null)
{
[Link]("[Link]");
}
%>
<div class="row">
<div class="card">
<div class="card-body" style="background-color: blue">
<h5 class="card-title">
</div>
</div>
</div>
<div class="card">
<div class="card-body" style="background-color: blue">
<h5 class="card-title">
</div>
</div>
</div>
</div>
</div>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<!-- navbar -->
<jsp:include page="[Link]"></jsp:include>
<%
String coursemsg=(String)[Link]("cmsg");
%>
<div class="container">
<div class="row">
<div class="col-md-6 offset-3">
<h3>Admin Dashboard</h3>
<div class="form-group">
<label for="lastinput">Course Duration</label> <input type="text"
name="cdur" class="form-control" id="lastinput"
aria-describedby="emailHelp" placeholder="Enter Course Duration">
</div>
<div class="form-group">
<label for="lastinput">Course Description</label>
<textarea name="cdesc" class="form-control" id="cdesc" rows="3"></textarea>
</div>
<div class="form-group">
<label for="lastinput">Course Fee</label>
<textarea name="cfee" class="form-control" id="cdesc" rows="3"></textarea>
</div>
<div class="form-group">
<label for="exampleFormControlFile1">Upload Course Image</label> <input
accept="image/*" required name="cpic" type="file" class="form-control-file"
id="exampleFormControlFile1">
</div>
<div class="form-group">
<label for="exampleFormControlFile1">Upload Course PDF</label> <input
accept=".pdf" name="cpdf" required type="file" class="form-control-file"
id="exampleFormControlFile1">
</div>
<%
if(coursemsg!=null && ![Link]())
{
%>
<%
}
%>
</div>
</div>
</div>
</body>
</html>
[Link]
body
{
background: rgb(238,174,202);
background: radial-gradient(circle, rgba(238,174,202,1) 0%, rgba(148,187,233,1) 100%);
}
Service
Courservice (interface)
import [Link];
import [Link];
public interface CourseService {
public boolean saveCourseDetail(Course c);
public List<Course> getAllCourses();
public List<Course> getTopSixCourse();
public String getCourseById(int cid);//fetching Course based
on idpublic Course getCourseBasedOnId(int id);//update
coursepublic boolean updateCourseData(Course c);//delete
public boolean deleteCourseById(int id);
}
Userservice
package service;
import [Link];
serviceImpl
CourseServiceImpl
public class CourseServiceImpl implements CourseService {
@Override
public boolean saveCourseDetail(Course c) {
return addCourse;
}
@Override
public List<Course> getAllCourses() {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
List<Course> allMyCourse = [Link]();
return allMyCourse;
}
@Override
public List<Course> getTopSixCourse() {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
List<Course> sixCourses = [Link]();
return sixCourses;
}
@Override
public String getCourseById(int cid) {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
@Override
public Course getCourseBasedOnId(int id) {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
Course course = [Link](id);
return course;
@Override
public boolean updateCourseData(Course c) {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
boolean res = [Link](c);
return res;
}
//
//delete
@Override
public boolean deleteCourseById(int id) {
// comunicate to dao
CourseDao cdao = new CourseDao([Link]());
boolean res = [Link](id);
return res;
}//end
userserviceImpl
public class UserServiceImpl implements UserService{
return isSaved;
}//method end
return user;
}//end
}//class end
Model
[Link]
public class User {
[Link]
public class Course {
[Link]
public class MyHelper {
boolean f = false;
try {
[Link]();
f = true;
} catch (Exception e) {
[Link]();
[Link]("file not saved in pics !!!");
return f;
if (![Link]()) {
[Link]();// creates directoty if not exist
}
[Link](finalPAth);
success = true;
} catch (Exception e) {
[Link]();
}
return success;
Daos
CourseDao
public class CourseDao {
boolean f = false;
try {
PreparedStatement ps = [Link](query);
[Link](1, [Link]());
[Link](2, [Link]());
[Link](3, [Link]());
[Link](4, [Link]());
[Link](5, [Link]());
[Link](6, [Link]());
[Link](7, [Link]());
if (res > 0) {
f = true;
}
} catch (Exception e) {
[Link]();
return f;
try {
PreparedStatement ps = [Link](query);
ResultSet rs = [Link]();
while ([Link]()) {
String cname = [Link]("coursename");
String cdur = [Link]("courseduraton");
int cfee = [Link]("coursefee");
String cimg = [Link]("courseimg");
int cid = [Link]("courseid");
int uid = [Link]("userid");
String cdesc = [Link]("coursedesc");
} catch (Exception e) {
[Link]();
return clist;
try {
PreparedStatement ps = [Link](query);
ResultSet rs = [Link]();
while ([Link]()) {
String cname = [Link]("coursename");
String cdur = [Link]("courseduraton");
int cfee = [Link]("coursefee");
String cimg = [Link]("courseimg");
int cid = [Link]("courseid");
int uid = [Link]("userid");
String cdesc = [Link]("coursedesc");
[Link](course);
} catch (Exception e) {
[Link]();
}
return clist;
}//
try {
String query = "select * from course where courseid=?";
PreparedStatement ps = [Link](query);
[Link](1, id);
ResultSet rs = [Link]();
if ([Link]()) {
pdfName = [Link]("pdfname");
} catch (Exception e) {
[Link]();
return pdfName;
try {
String query = "select * from course where courseid=?";
PreparedStatement ps = [Link](query);
[Link](1, id);
ResultSet rs = [Link]();
if ([Link]()) {
[Link](cdesc);
[Link](cdur);
[Link](cfee);
[Link](cid);
[Link](cimg);
[Link](pdfname);
[Link](cname);
} catch (Exception e) {
[Link]();
}
return c;
// update method
try {
// when pdf and image both uploaded
[Link]();
f = true;
[Link]();
f = true;
[Link]();
f = true;
[Link]();
f = true;
} catch (Exception e) {
[Link]();
}
return f;
}//
try {
String query = "delete from course where courseid=?";
PreparedStatement ps = [Link](query);
[Link](1, id);
if(res>0)
{
f=true;
}else
{
f=false;
}
} catch (Exception e) {
return f;
Logindao
public class LoginDao {
try {
if ([Link]()) {
user = new User();// empty
[Link](mob);
[Link](uemail);
[Link](fname);
[Link](picname);
[Link](lname);
[Link](uid);
[Link](role);
} catch (Exception e) {
[Link]();
return user;
}// end
Registerdao
public class RegisterDao {
try {
PreparedStatement ps = [Link](query);
[Link](1, [Link]());
[Link](2, [Link]());
[Link](3, [Link]());
[Link](4, [Link]());
[Link](5, [Link]());
[Link](6, [Link]());
[Link](7, [Link]());
int res = [Link]();
if (res > 0) {
f = true;
}
} catch (Exception e) {
[Link]();
return f;
Userdao
public class UserDao {
try
{
ResultSet rs = [Link]();
if([Link]())
{
userName = [Link]("firstname");
}
}catch(Exception e)
{
[Link]();
return userName;
}
Controllers
AddCourseController
@WebServlet("/addcourse")
@MultipartConfig
public class AddCourseController extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
[Link]("text/html");
PrintWriter wrt = [Link]();
if(cmessage==null)
{
// if([Link]()>1024*1024*5)
// {
//
// }
//working on pdf part
Part pdfPart = [Link]("cpdf");
String pdfPath=[Link]("/")+"pdfs";
if(isPdfSaved)
{
if(isimageSaved)
{
//now after saving image and pdf to folder we are ready to save whole course object to
//database
if(isSaved)
{
[Link]("cmsg", "course added succesfully!!!");
}else
{
[Link]("cmsg", "Something Went Wrong!!!");
}
RequestDispatcher rd = [Link]("[Link]");
[Link](req, resp);
}
[Link]("cmsg");
}else
{
[Link]("cmsg");
[Link]("[Link]");
Deletecontroller
@WebServlet("/delete")
public class DeleteController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
//service
CourseService cs=new CourseServiceImpl();
if(res)
{
[Link]("[Link]");
}else
{
[Link]("del", "unable to delete something went wrong!!!!");
RequestDispatcher rd = [Link]("[Link]");
[Link](req, resp);
}
}
}
Downloadsyllabuscontroller
@WebServlet("/getsyllabus")
public class DownloadSyllabusController extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
[Link]("application/pdf");
[Link]("Content-Disposition","attachment;filename=\""+pdfname+"\"");
String path=[Link]("/")+"pdfs"+[Link]+pdfname;
[Link](b);
ServletOutputStream os = [Link]();
[Link](b);
[Link]();
Editcourse
@WebServlet("/editcourse")
@MultipartConfig
public class EditCourse extends HttpServlet{
//delete left
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
int courseId=[Link](cid);
int fee=[Link](cfee);
[Link](uid);
//check condition based on image and pdf
//check pdf
[Link](req, path);
String
path=[Link]("/")+"coursepic"+[Link]+[Link]();
[Link]([Link](),path);
if(res)
{
[Link]("update", "course updated succesfully!!!");
}else
{
[Link]("update", "something went Wrong please check!!!");
}
RequestDispatcher rd = [Link]("[Link]");
[Link](req, resp);
Logincontroller
@WebServlet("/login")
public class LoginController extends HttpServlet {
//doget-->GET request
//dopost -->post
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter wrt = [Link]();
HttpSession session=[Link]();
[Link]("loggedinUSer", user);
[Link]("[Link]");
}else if(user!=null)
{
HttpSession session=[Link]();
[Link]("loggedinUSer", user);
[Link]("[Link]");
}else
{
String msg="Invalid credentials !!!";
HttpSession session=[Link]();
[Link]("loginmsg", msg);
[Link]("[Link]");
}
Logoutcontroller
@WebServlet("/logout")
public class LogoutController extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter wrt = [Link]();
[Link]();//session destroy
[Link]("logoutMessage", logoutMsg);
RequestDispatcher rd = [Link]("[Link]");
[Link](req, resp);
Registercontroller
@WebServlet("/signup")
@MultipartConfig
public class RegisterController extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter wrt = [Link]();
String newprofilePic=newtimestamp+"_"+picname;
//file path
String path=[Link]("/")+"pics"+[Link]+[Link]();
if(isSaved)
{
//file saved to pics folder
if(res)
{
[Link]("user register succesfully!!!");
}else
{
[Link]("soemthing went wrong!!!");
}
}
DBConnection
public class DBConnection {
try {
if (conn == null) {
[Link]("[Link]");
conn =
[Link]("jdbc:mysql://localhost:3306/mycourse", "root", "root");
} catch (Exception e) {
[Link]("some thing wrong in db connection !!!");
[Link]();
}
return conn;
}