Docsity

Enterprises Java Programming practical Document, Assignments of Java Programming

Toggle sidebar
bg1
Name - Saikiran Machagoni
Class - TYIT - D
Subject - Enterprise Java
Roll no - 8621
Teacher In-Charge - Omkar Sherkhane.
Index
Sr.No
Practical
Date
1)
Implement the following Simple Servlet applications.
a) Create a simple calculator application using servlet.
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”.
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.
2)
Implement the following Servlet applications with Cookies
and Sessions. Implement the following Servlet applications
with Cookies and Sessions.
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.
b) Create a servlet that uses Cookies to store the number of
times a user has visited servlet
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.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63

Partial preview of the text

Download Enterprises Java Programming practical Document and more Assignments Java Programming in PDF only on Docsity!

Name - Saikiran Machagoni Class - TYIT - D Subject - Enterprise Java Roll no - 8621 Teacher In-Charge - Omkar Sherkhane. **Index Sr.No Practical Date

  1. Implement the following Simple Servlet applications.** a) Create a simple calculator application using servlet. b) Create a servlet for a login page. If the username and password are correct then it says message “Hello ” else a message “login failed”. 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. 2) Implement the following Servlet applications with Cookies and Sessions. Implement the following Servlet applications with Cookies and Sessions. 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. b) Create a servlet that uses Cookies to store the number of times a user has visited servlet 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.

3) Implement the Servlet IO and File applications. a) Create a Servlet application to upload and download a file. b) Develop Simple Servlet Question Answer Application using Database. c) Create simple Servlet application to demonstrate Non-Blocking Read Operation. 4) Implement the following JSP applications. a) Develop a simple JSP application to display values obtained from the use of intrinsic objects of various types. 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). c) Create a registration and login JSP application to register and authenticate the user based on username and password using JDBC. 5) Implement the following JSP JSTL and EL Applications. 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 b) Create a JSP page to demonstrate the use of Expression language. c) Create a JSP application to demonstrate the use of JSTL. 6) Implement the following EJB Applications. a) Create a Currency Converter application using EJB. b) Develop a Simple Room Reservation System Application Using EJB. c) Develop simple application which work with Interceptors & JNDI.

Practical No - 1 Implement the following Simple Servlet applications. a) Create a simple calculator application using servlet. Input - Html -

Calculator Multiple

Enter 1st no. Enter 2nd no.

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; @WebServlet(urlPatterns = {"/calcu_multiple"}) public class calcu_multiple extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { int a = Integer.parseInt(request.getParameter("t1")); int b = Integer.parseInt(request.getParameter("t2")); if(request.getParameter("add")!=null) { int c=a+b; out.println("addition = "+c); } if(request.getParameter("sub")!=null) { int d=a-b; out.println("Subtraction = "+d); } if(request.getParameter("multiply")!=null) { int e=a*b; out.println("Multiply = "+e); } if(request.getParameter("divison")!=null) { int f=a/b; out.println("division = "+f);

b) Create a servlet for a login page. If the username and password are correct then it says message “Hello ” else a message “login failed”. Input - Html -

Login

Enter User Name : Enter Password :

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; @WebServlet(urlPatterns = {"/authentication"}) public class authentication extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String u=request.getParameter("t1"); String p=request.getParameter("t2"); if(u.equals("Admin") && p.equals("123")) { out.println("Welcome") } else { out.println("Login Failed"); } }catch(Exception e) {out.println("Error" +e);} } } 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 registration details in the database. Input - HTML -

Database Practical 1 c

Username Password Email id Country

Servlet - 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.; /*

  • @author saikiranmachagoni */ @WebServlet(urlPatterns = {"/prac1c"}) public class prac1c extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String u= request.getParameter("t1"); String p=request.getParameter("t2"); String em=request.getParameter("t3"); String co=request.getParameter("t4"); Class.forName("com.mysql.jdbc.Driver"); Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/prac1c","root","saiki ran"); PreparedStatement ps=c.prepareStatement("insert into new_table values (?,?,?,?)"); ps.setString(1,u); ps.setString(2, p); ps.setString(3, em); ps.setString(4, co); int i=ps.executeUpdate(); if(i>0) { out.println("Data Saved");

2) Implement the following Servlet Application with Cookies and Sessions. a) Using Request Dispatcher Interface create a Servlet that will validate the password entered by the user, if the user has entered "Servlet" as a 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. Input -

Practical 2 A

Username Password

Main.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 javax.servlet.RequestDispatcher; /**

}catch(Exception e){out.println("Error "+e);} } } Welcome.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 javax.servlet.RequestDispatcher; /**

  • @author saikiranmachagoni / @WebServlet(urlPatterns = {"/welcome"}) public class welcome extends HttpServlet { /*
  • Processes requests for both HTTP GET and POST
  • methods.
  • @param request servlet request
  • @param response servlet response
  • @throws ServletException if a servlet-specific error occurs
  • @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String u=request.getParameter("t1"); out.println("Welcome "+u); }catch(Exception e){out.println("Error "+e);} } } Output -

response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String u= request.getParameter("t1"); String p=request.getParameter("t2"); if(u.equals("Saikiran")&& p.equals("123")) { Cookie c1 = new Cookie("Username",u); Cookie c2 = new Cookie("Password",p); response.addCookie(c1); response.addCookie(c2); response.sendRedirect("admin_home"); } else { out.println("Invalid Username/Password"); } } catch(Exception e) { out.println("Error="+e); } } } Admin Home.java import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = {"/admin_home"}) public class admin_home extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { Cookie []a = request.getCookies(); String x =a[0].getValue(); String y =a[1].getValue(); out.println("Welcome 8621 :"+x); out.println("This is Your Password:"+y); } catch(Exception e) { out.println("Error="+e); } } } Output