



























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























































































Name - Saikiran Machagoni Class - TYIT - D Subject - Enterprise Java Roll no - 8621 Teacher In-Charge - Omkar Sherkhane. **Index Sr.No Practical Date
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.; /*
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; /**
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