WebProgram to Study PDF

Document Details

ExpansiveMossAgate7745

Uploaded by ExpansiveMossAgate7745

Jazan University

Tags

web programming html jsp servlet

Summary

This document contains exercises and examples for learning web programming using HTML, JSP, and Servlet technologies. It provides step-by-step instructions and code snippets for understanding different concepts.

Full Transcript

417Comp-3 Enterprise Application Development Online programs for HTML, JSP & Servlet Download anyone of the Web Servers from the list in of NetBeans. Recommended is Payara Web Server. Exercise: 1 Write an HTML program of Welcome. Insert a new file by right-click on project and...

417Comp-3 Enterprise Application Development Online programs for HTML, JSP & Servlet Download anyone of the Web Servers from the list in of NetBeans. Recommended is Payara Web Server. Exercise: 1 Write an HTML program of Welcome. Insert a new file by right-click on project and New → HTML. File Name: NewWelcome.html My First HTML Program WELCOME TO HTML PROGRAMMING Exercise: 2 Write a SERVLET program of Welcome. Insert a new file by right-click on project and New → SERVLET. Servlet File Name : myCalc.java import java.io.IOException; import java.io.PrintWriter; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = {"/myCalc"}) public class myCalc extends HttpServlet { private String message; public void init() throws ServletException{ message = "Hello Servlet World!"; } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("" + message + ""); out.close(); } public void destroy(){ } } Exercise: 3 Write a JSP program for arithmetic calculations. File Name: UserLogin.html Login Screen Enter your Credentials Name : Password: Servlet File Name: CheckPass.java import java.io.IOException; import java.io.PrintWriter; import java.io.*; import jakarta.servlet.*; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @WebServlet(urlPatterns = {"/CheckPass"}) public class CheckPass extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String n = request.getParameter("userName"); String p = request.getParameter("userPass"); if(p.equals("servlet")){ RequestDispatcher rd = request.getRequestDispatcher("myCalc"); rd.forward(request, response); } else{ out.print("Sorry User Name or Password Error!"); RequestDispatcher rd=request.getRequestDispatcher("UserLogin.html"); rd.include(request, response); } } } Exercise: 4 Write a JSP program for arithmetic calculations. File Name: ArithCalc.html EAD Registration Form Calculation Form First Number Second Number JSP File Name: myNCalc.jsp JSP Page Calculation! The Arithmetic Calculations Sum : Sub : Mul : Div : Mod : Exercise: 5 Write a JSP program to read the names as parameters. File Name: NamePara.html Servlet Parameter Reading Enter your name First Name: Second Name: Third Name: Servlet File Name: ParamRead.java import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.PrintWriter; @WebServlet(urlPatterns = {"/ParamRead"}) public class ParamRead extends HttpServlet { private static final long serialVersionUID = 1L; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String param1 = request.getParameter("Param1"); String param2 = request.getParameter("Param2"); String param3 = request.getParameter("Param3"); PrintWriter out = response.getWriter(); out.println(" First Name :"+param1+""); out.println(" Second Name :"+param2+""); out.println(" Third Name :"+param3+""); response.getWriter().println("Parameters received successfully!"); out.close(); } }

Use Quizgecko on...
Browser
Browser