8423 Tejas Java Practical
8423 Tejas Java Practical
Seat no. 8427 has successfully completed all the practicals of the subject Enterprise Java
Internal Examiner
a Create an html page with fields, eno, name, age, desg, salary. Now
. submit this data to a JSP page which will update the employee table
of the database with matching eno.
b Create a JSP page to demonstrate the use of Expression language.
.
c Create a JSP application to demonstrate the use of JSTL.
.
Index.html:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
</form>
</body>
</html>
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
response.setContentType("text/html;charset=UTF-8");
try {
int i = Integer.parseInt(request.getParameter("t1"));
int j= Integer.parseInt(request.getParameter("t2"));
if(request.getParameter("add")!=null){
out.println("Addition is :"+(i+j));
if(request.getParameter("sub")!=null){
out.println("Subtraction is :"+(i-j));
if(request.getParameter("mult")!=null){
out.println("Multiplication is :"+(i*j));
}
if(request.getParameter("div")!=null){
out.println("division is :"+(i/j));
}catch(Exception e){
out.println("error :"+e);
OUTPUT-:
b. Create a servlet for a login page. If the username and password are correct then it says
message “Hello <username>” else a message “login failed”
index.html
<html>
<head>
<title>Login Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="login" method="get">
<input type="text" name="user" placeholder="Username"><br>
<input type="password" name="pass" placeholder="Password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
login.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(urlPatterns={"/login"})
public class login extends HttpServlet{
public void doGet(HttpServletRequest req , HttpServletResponse res) throws ServletException ,
IOException {
res.setContentType("Text/Html");
PrintWriter out = res.getWriter();
String name = req.getParameter("user");
String pas = req.getParameter("pass");
if(name.equals("shivendra") && pas.equals("8637"))
{
out.println("Welcome " + name );
}
else{
res.sendRedirect("index.html");
}
} }
Output:
c. Create a registration servlet in Java using JDBC. Accept the details such as Username,
Password, Email, and Country from the user using HTML Form and store the registration
details in the database.
index.html:
<html>
<head>
<title>Registration using JDBC</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="signup" method="get">
<input type="text" name="user" placeholder="Enter your name"><br>
<input type="email" name="email" placeholder="Enter your email"><br>
<input type="password" name="pass" placeholder="Enter your password"><br>
<input type="text" name="cn" placeholder="Enter your country"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
signup.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.sql.*;
@WebServlet(urlPatterns={"/signup"})
public class signup extends HttpServlet{
public void doGet(HttpServletRequest request , HttpServletResponse response)
throws ServletException , IOException{
response.setContentType("Text/Html");
PrintWriter out = response.getWriter();
try{
String name = request.getParameter("user");
String pas = request.getParameter("pass");
String email = request.getParameter("email");
String country = request.getParameter("cn");
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection cn =
DriverManager.getConnection("jdbc:derby://localhost:1527/record","app","app");
PreparedStatement ps = cn.prepareStatement("insert into record values(?,?,?,?)");
ps.setString(1, name);
ps.setString(2, pas);
ps.setString(3, email);
ps.setString(4, country);
int i = ps.executeUpdate();
if(i>0){
out.println("Data saved successfully");
}
else{
out.println("Data save failed");
}}
catch(Exception e){
out.println("error :"+e);
}
}
Output-
Practical 2
a. Using Request dispatcher Interface create a Servlet which will validate the password
entered by the user, if the user has entered "Servlet" as password, then he
will be forwarded to Welcome Servlet else the user will stay on the index.html page and
an error message will be displayed.
index.html:
<html>
<head>
</head>
<body>
<form action="login" method="post">
Password: <input type="password" name="t2"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
login.java:
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(urlPatterns={"/login"})
public class login extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("Text/Html");
PrintWriter out = response.getWriter();
try{
String pa = request.getParameter("t2");
if(pa.equals("servlet")){
RequestDispatcher rd = request.getRequestDispatcher("owner");
rd.forward(request,response);
}
else{
out.println("Please enter valid password");
response.sendRedirect("index.html");
}
}
catch(Exception e){
out.println("Error : "+e);
}
} }
owner.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
@WebServlet(urlPatterns={"/owner"})
public class owner extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("Text/Html");
PrintWriter out=response.getWriter();
try{
String u = request.getParameter("t2");
out.println("Welcome "+u);
}
catch(Exception e){
out.println("error "+e);
}
}}
Output:
b. Create a servlet that uses Cookies to store the number of
times a user has visited servlet
logic.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(urlPatterns={"/logic"})
public class logic extends HttpServlet{
static int i=1;
public void service(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("Text/Html");
PrintWriter out= response.getWriter();
try{
Cookie c= new Cookie("user_name",String.valueOf(i));
response.addCookie(c);
int j =Integer.parseInt(c.getValue());
if(j==1){
out.println("Welcome user");
}
else{
out.println("You have visited this website "+j+" time");
}
i++;
}
catch(Exception e){
out.println("Error "+e);
}
}
}
Output:
c. Create a servlet demonstrating the use of session creation and destruction. Also check
whether the user has visited this page first time or has visited earlier also using sessions.
login.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(urlPatterns={"/login"})
public class login extends HttpServlet{
static int i;
public void service(HttpServletRequest request,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("Text/Html");
PrintWriter out= response.getWriter();
try{
HttpSession session = request.getSession(true);
if(session.isNew()){
out.println("Welcome , Shiv");
i=0;
}
else{
out.println("Welcome Again");
i++;
}
out.println("<br>Number of previous Accesses :"+i);
}
catch(Exception e){
out.println("Error "+e);
} } }
Output:
Practical 3
index.html
<!DOCTYPE html>
<html>
<head>
<title>Quiz Application</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>Quiz</h1>
<form action="QuizServlet" method="get">
<label>Java Enterprise Edition, is also known as?</label><br>
<input type="radio" name="q1" value="a">J2EE<br>
<input type="radio" name="q1" value="b">J2SE<br>
<input type="radio" name="q1" value="c">J2ME<br>
<br><br>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</form>
</body>
</html>
QuizServlet.java
import java.io.IOException;
import java.io.PrintWriter;
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.*;
import java.util.*;
@WebServlet(urlPatterns = {"/QuizServlet"})
public class QuizServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String paramName, paramValue[];
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
int cnt=0;
String ans="";
con=DriverManager.getConnection("jdbc:derby://localhost:1527/College","app","app");
stmt=con.createStatement();
rs=stmt.executeQuery("select ans from quiz");
while(rs.next()&& paramNames.hasMoreElements())
{
String un=rs.getString(1);
paramName = (String)paramNames.nextElement();
paramValue = request.getParameterValues(paramName);
for(int i=0;i<paramValue.length;i++)
{
ans = paramValue[i];
}
if(un.equals(ans))
cnt++;
}
out.println("<h1>You have scored "+cnt+" points out of 3.</h1>");
}catch(Exception e){out.println("Error: "+e);}
}
}
OUTPUT:
Practical 4
a. Develop a simple JSP application to display values obtained from the use of intrinsic
objects of various
types.
Index.html:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="ImpObject.jsp" method="post">
Enter your class :<input type="text" name="t1"><br>
<input type="submit" value="request/out" name="detail"><br><br>
ImpObject.jsp :
Second.jsp :
Output-
b. Develop a simple JSP application to pass values from one page to another with
validations. (Name-txt, age- txt, hobbies-checkbox, email-txt, gender-radio button).
Index.html :
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="form.jsp" method="post">
Enter your name<input type="text" name="t1"><br>
Enter your age <input type="number" name="t2"><br>
Enter your email <input type="email" name="t3"><br>
Please select your hobbies <input type="checkbox" name="check1" value="play" >Playing
<input type="checkbox" name="check1" value="swimming" >swimming<br><br>
Gender <input type="radio" name="gen" value="Male"> Male
<input type="radio" name="gen" value="Female"> Female<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
form.jsp :
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*,java.io.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name = request.getParameter("t1");
int age = Integer.parseInt(request.getParameter("t2"));
String email = request.getParameter("t3");
String hobbies = request.getParameter("check1");
String gender = request.getParameter("gen");
RequestDispatcher rd= request.getRequestDispatcher("form2.jsp");
rd.forward(request, response);
%
</body>
</html>
form2.jsp :
Output:
c. Create a registration and login JSP application to register and authenticate the user
based on username and password using JDBC.
Index.html :
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="reg.jsp" method="post">
Enter name: <input type="text" name="t1"><br>
Enter username (email): <input type="email" name="t2"><br>
Enter pass:<input type="password" name="t3"><br>
Re enter password: <input type="password" name="t4"><br>
<input type="submit" value="REGISTER" name="b1">
</form>
</body>
</html>
Reg.jsp:
Login.html :
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="Login.jsp" method="POST">
Enter username: <input type="email" name="t1"><br>
Enter pass: <input type="password" name="t2"><br>
<input type="submit" value="LOGIN" name="b1">
</form>
</body>
</html>
Login.jsp :
Admin.jsp :
Output-
PRACTICAL 5
A. CREATE AN HTML PAGE WITH FIELDS, ENO, NAME, AGE, DESG, SALARY. NOW ON
SUBMIT THIS DATA
TO A JSP PAGE WHICH WILL UPDATE THE EMPLOYEE TABLE OF
DATABASE WITH MATCHING ENO.
INPUT:-
Index.html
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="UpdateEmp.jsp" >
Enter Employee Number<input type="text" name="txtEno" ><br> Enter
Name<input type="text" name="txtName" ><br>
Enter age<input type="text" name="txtAge" ><br> Enter
0Salary<input type="text" name="txtSal" ><br>
<input type="reset" ><input type="submit">
</form>
</body>
</html>
UpdateEmp.jsp
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Employee Record Update</h1>
<%
String eno=request.getParameter("txtEno"); String
name=request.getParameter("txtName"); String age =
request.getParameter("txtAge"); String sal =
request.getParameter("txtSal");
try{ Class.forName("com.mysql.jdbc.Driver"); Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/C","root","root"); PreparedStatement stmt =
con.prepareStatement("select * from emp where empid=?"); stmt.setString(1, eno);
ResultSet rs = stmt.executeQuery(); if(rs.next()){
out.println("<h1>~~~ Employee "+name+" Exist ~~~ </h1>");
PreparedStatement pst1= con.prepareStatement("update emp set salary=? where empid=?");
PreparedStatement pst2= con.prepareStatement("update emp set age=? where empid=?");
pst1.setString(1, sal);
pst1.setString(2, eno);
pst2.setString(1, age);
pst2.setString(2, eno);
pst1.executeUpdate();
pst2.executeUpdate();
}else{
out.println("<h1>Employee Record not exist !!!!!</h1>");
}}catch(Exception e){out.println(e);}%>
</body>
</html>
OUTPUT:-
PRACTICAL NO: 6
currency.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import javax.ejb.Stateless;
/**
*
* @author student
*/
@Stateless
public class currency implements currencyRemote {
@Override
public float currencyMethod(int a)
{ return a*80;
}
@Override
public float dollartoinr(float a) { return
0.0F;
}
}
currencyremote.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import javax.ejb.Remote;
/**
*
* @author student
*/ @Remote
public interface currencyRemote { float
a);
Main.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package applicationclient1;
/**
*
* @author student
*/
public class Main {
@EJB
private static currencyRemote currency;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here float f =
currency.currencyMethod(10); System.out.println(f);
}
6(B) DEVELOP SIMPLE BANK APPLICATION USING EJB [STATEFUL
SESSION BEAN].
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="banking" method="post">
banking.java
package p1;
import java.io.IOException;
import java.io.PrintWriter;
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.ejb.*;
@EJB
p1.BankLocal b;
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
}
if (request.getParameter("with") != null) {
boolean status = b.withdraw(Integer.parseInt(amount));
if (status) {
bankLocal.java
package p1;
import javax.ejb.Local;
@Local
int getBalance();
Bank.java
package p1;
import javax.ejb.Stateful;
@Stateful
this.amount-=amount;
return true;
}else{
return false;
}
}
public void deposit(int amount){
this.amount+=amount;
}
}
Output-
Check balance
Deposit
withdraw
PRACTICAL: 7
INPUT:-
Index.html
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>TODO write content</div>
<h1>Welcome to Hit Count Page</h1> Page was hit #{count.hitCount} times<h1/>
</body>
</html>
package mypack;
import java.io.Serializable; import
javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import
javax.inject.Named;
import counter.ejb.CounterBean; @Named("count")
@ConversationScoped public class Count implements
Serializable {
@EJB
@Singleton
public class CounterBean { private int hits = 1; public int
getHits() {
return hits++;
}}
OUTPUT:-
PRACTICAL 8
8(A) IMPLEMENT THE FOLLOWING JPA APPLICATIONS.
CREATE A SIMPLE JPA APPLICATION TO PERFORM CRUD OPERATIONS
ON BOOK DETAILS. BOOK DETAILS LIKE BOOK_ID, BOOK_NAME,
BOOK_PRICE, BOOK_PRICE, BOOK_AUTHOR, BOOK_PUBLICATION
.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="jpa.jsp" method="POST">
<table>
<tr><td>Enter book id</td><td> <input type="number" name="id"></td></tr>
<tr><td>Enter book Name</td><td> <input type="text" name="name"></td></tr>
</table>
</br> </br>
<input type="submit" name="save" value="SAVE">
<input type="submit" name="ret" value="retrive">
<input type="submit" name="up" value="update">
<input type="submit" name="del" value="delete">
</form>
</body>
</html>
Jpa.jsp
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
if (request.getParameter("save") != null) {
em.getTransaction().begin();
if (request.getParameter("ret") != null) {
em.getTransaction().begin();
}
out.println("</table>");
em.getTransaction().commit();
}
if (request.getParameter("up") != null) {
em.getTransaction().begin();
Book b=em.find(Book.class,id);
b.setB_price(price);
em.getTransaction().commit();
out.print("data updated");
}
if (request.getParameter("del") != null) {
em.getTransaction().begin();
Book b=em.find(Book.class,id);
em.remove(b);
em.getTransaction().commit();
out.println("row deleted");
em.close();
emf.close();
%>
</body>
</html>
Book.java
package p1;
import java.io.*;
import javax.persistence.*;
@Entity
public class Book implements Serializable
{ private static final long serialVersionUID =
1L; @Id
}
public void setB_ath(String b_ath) {
this.b_ath = b_ath;
}
}
Output-
Retrieve
Update
PRACTICAL 9
9(A) IMPLEMENT THE FOLLOWING JPA APPLICATIONS WITH ORM
AND HIBERNATE.
.HTML
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="hb.jsp" method="post">
enter your name<input type="text" name="name"></br> </br>
enter your email<input type="email" name="email"></br></br>
hb.jsp
<%@page contentType="text/html" import="org.hibernate.*"
import="org.hibernate.cfg.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String name=request.getParameter("name");
String email=request.getParameter("email");
String feed=request.getParameter("fed");
SessionFactory sf=new
Configuration().configure("hibernate.cfg.xml").buildSessionFactory()
;
Session s=sf.openSession();
Transaction t=s.beginTransaction();
p1.Pojo e=new p1.Pojo();
e.setF_email(email);
e.setF_name(name);
e.setF_fed(feed);
s.save(e);
t.commit();
s.close();
out.println("<script>alert('feddback saved');window.location.href='index.html'</script>")
%>
</body>
</html>
hb.java
package p1;
import javax.persistence.*;
@Entity
@Table(name="feedback")
public class Pojo {
@Id
private String f_email;
@Column
return f_email;
}
public void setF_email(String f_email) {
this.f_email = f_email;
}
public String getF_name() {
return f_name;
}
public String getF_fed() {
return f_fed;
}
public void setF_fed(String f_fed) {
this.f_fed = f_fed;
}
}
Hibernate.cfg.xml
Output-
0
Delete
9(B) DEVELOP A HIBERNATE APPLICATION TO PERFORM CRUD
OPERATION ON EMPLOYEE DETAILS IN MYSQL DATABASE.
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="emp.jsp" method="post">
<table>
<tr><td>enter employee id</td><td><input type="text" name="id"></td></tr>
<tr><td>enter employee name</td><td><input type="text" name="name"></td></tr>
<tr><td>employee phone number</td><td><input type="text" name="number"></td></tr>
<tr><td>employee salary </td><td><input type="text" name="sal"></td></tr>
</table>
</br>
<input type="submit" name="save" value="save">
<input type="submit" name="ret" value="show">
<input type="submit" name="update" value="update">
<input type="submit" name="del" value="delete" >
</form>
</body>
</html>
emp.,jsp
SessionFactory sf = new
Configuration().configure("hybernate1.cfg.xml").buildSessionFactory();
Session s = sf.openSession();
if (request.getParameter("save") != null) {
Transaction t = s.beginTransaction();
p1.Emp e = new p1.Emp();
e.setE_id(id);
e.setE_name(name);
e.setE_phone(phone);
e.setE_sal(sal);
s.save(e);
t.commit();
s.close();
out.println("<script>alert('data saved');window.location.href='emp.html'</script>");
}
if (request.getParameter("ret") != null) {
Transaction t = s.beginTransaction();
p1.Emp e = new p1.Emp();
while (itr.hasNext()) {
out.println("<tr>");
} out.println("</table>");
t.commit();
s.close();
}
if (request.getParameter("update") != null) {
Transaction t = s.beginTransaction();
p1.Emp em = (p1.Emp)s.get(p1.Emp.class,id);
em.setE_name(name);
s.update(em);
t.commit();
s.close();
out.println("data saved");
}
try{
if (request.getParameter("del") != null) {
Transaction t = s.beginTransaction();
p1.Emp em = (p1.Emp)s.get(p1.Emp.class,id);
s.delete(em);
t.commit();
s.close();
out.println("data deletd");
}catch(Exception e){
out.print(e);
}
%>
</body>
</html>
emp.java
package p1;
import javax.persistence.*;
@Entity
@Table(name = "Emp")
public class Emp {
@Id
private String e_id;
@Column
return e_id;
}
public void setE_id(String e_id) {
this.e_id = e_id;
}
public void setE_name(String e_name) {
this.e_name = e_name;
}
public void setE_sal(String e_sal) {
this.e_sal = e_sal;
}
}
Hybernate.cfg.xml
Output
Retrieve
Update
Delete
PRACTICAL 10
10) DEVELOP A FIVE PAGE WEB APPLICATION SITE USING ANY TWO OR
THREE JAVA EE TECHNOLOGIES.
E-commerce
website
Welcome.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<center>
<h1>electronics E-shop</h1>
<h3>
shop online here with grate discounts !!!!</h3></br>
<a href="login.html"><button>login</button></a>
<a href="register.html"><button>register here</button></a>
</center>
</body>
</html>
Output
Register page
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="register.jsp" method="post">
<h1>register here</h1>
<table>
<tr>
<td>Enter Name:</td><td><input type="text" name="name"></td>
</tr>
<tr>
<td>Enter Email:</td><td><input type="text" name="email"></td></tr>
<tr>
<td>Enter User_Name :</td><td> <input type="text" name="username"></td>
</tr>
<tr>
<td>Enter password:</td>
<td><input type="password" name="pass"></td></tr>
</table><br>
<input type="submit" name="n1" value="Register">
</form>
</body>
</html>
Register.jsp
String name=request.getParameter("name");
String pass=request.getParameter("pass");
String email=request.getParameter("email");
String username=request.getParameter("username");
Class.forName("com.mysql.jdbc.Driver");
Connection
c=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
PreparedStatement ps=c.prepareStatement("insert into tyit values(?,?,?,?)");
ps.setString(1,name);
ps.setString(2,email);
ps.setString(3,username);
ps.setString(4,pass);
ps.executeUpdate();
ps.close();
c.close();
out.println("<script>alert('data saved');window.location.href='login.html'</script>");
%>
</body>
</html>
Output
Login page
Login.html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="login.jsp" method="post">
username <input type="text" name="uname"></br>
password <input type="text" name="pass"></br>
<input type="submit" name="t1">
</form>
</body>
</html>
Login.jsp
session.setAttribute("username",name);
response.sendRedirect("homepage.jsp");
break;
}
}
out.println("<script>alert('invalid username and
password')window.location.href='login.html'</script>");
Output:
%>
</body>
</html>
RS.close();
ps.close();
c.close();
Homepage
Homepage.jsp
<h1>electronics e-SHOP</h1>
<h3>
shop by category
</h3>
<table>
<tr>
<td><img src="tv.jpg" height="70" width="100" alt="tv"></td>
<td><img src="laptop.jpg" height="100" width="100" alt="laptop"></td>
<td><img src="washing.jpg" height="100" width="160" alt="wshing machine"></td>
</tr>
<tr>
<td>washing machine</td>
<td> laptop</td>
<td> tv</td>
</tr>
</table>
</br></br>
products
<table border="1">
<tr>
<td><image src="phone.jpg" height="100" width="100"></td>
<td>samsung galaxy fold </br> price=52000/- </td>
<td><a href="product.jsp?pd=4"> product description</a></td>
</tr>
<tr>
<td><image src="laptop.jpg" height="100" width="100"></td>
<td>HP chromebook</br> price=30000/- </td>
<td><a href="product.jsp?pd=2"> product description</a></td>
</tr>
<tr>
<td><image src="washing.jpg" height="100" width="100"></td>
<td>one plus Smart TV </br> price=14000/- </td>
<td><a href="product.jsp?pd=3"> product description</a></td>
</tr>
</table>
</body>
</html>
Output
Product details page
ProductDetail.jsp
<%--
Document : product
Created on : Oct 17, 2020, 6:54:28 PM
Author : Admin
--%>
p_id=RS.getString(1);
if(p_id.equals(id))
{
out.println("<td rowspan='6'>");
out.println("<img src='"+RS.getString(2)+"'>"+"</td>");
out.println("<td>"+RS.getString(3)+"</td>");
out.println("</tr>");
out.println("<tr><td>"+RS.getString(4)+"</td></tr>");
out.println("<tr><td>"+RS.getString(5)+" warranty<td></tr>");
out.println("<tr><td>mfg by "+RS.getString(6)+"<td></tr>");
out.println("<tr><td>price "+RS.getString(7)+"<td></tr>");
out.println("<tr><td><a href='cart.jsp?pd="+id+"'><button>add to
cart</button></a> <a href='buy.jsp'><button>buy
product</button></a></td></tr>");
out.println("</table>");
}
}
%>
</body>
</html>
output
Cart page
Cart.jsp
<%--
Document : cart.jsp
Created on : Oct 17, 2020, 6:31:49 PM
Author : Admin
--%>
<%
String p_id;
String id = request.getParameter("pd");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "");
PreparedStatement ps = c.prepareStatement("select * from pd");
ResultSet RS = ps.executeQuery();
while (RS.next()) {
p_id = RS.getString(1);
if (p_id.equals(id)) {
out.println("<tr>");
out.println("<td>" + "<img src='" + RS.getString(2) + "'>" + "</td>");
out.println("<td>" + RS.getString(3) + "</td>");
}
}
%>
</table>
</body>
</html>
Output