350 likes | 495 Views
**** Java Certification Training: https://www.edureka.co/java-j2ee-soa-training ****<br>This Edureka tutorial on u201cServlet and JSP tutorialu201d will talk about the basics of the World Wide Web and its components. It will tell you the fundamental concepts of servlets and JSP, its life cycle and various steps to create Servlet and Java Server Pages. Also, it will talk about Session Tracking and JSP Request and Response Methods. Through this tutorial you will learn the following topics:<br><br>Web & HTTP <br>Servlet Life Cycle<br>Steps to create Servlet<br>Generic Servlet<br>Session Tracking<br>Introduction to JSP<br>JSP Life Cycle-<br>JSP Scripting and Directive Elements<br>Java Bean Class<br>Check out our Java Tutorial blog series: https://goo.gl/osrGrS<br><br>Check out our complete Youtube playlist here: https://goo.gl/gMFLx3<br><br>Follow us to never miss an update in the future.<br><br>Instagram: https://www.instagram.com/edureka_learning/<br>Facebook: https://www.facebook.com/edurekaIN/<br>Twitter: https://twitter.com/edurekain<br>LinkedIn: https://www.linkedin.com/company/edureka
E N D
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Topics to be covered Introduction to JSP Introduction to Web 01 05 Introduction to Servlets Steps to create JSP 02 06 Generic Servlets JSP Scripting & Directive Elements 03 07 Session Tracking 04 Java Bean Class 08 JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Introduction to WEB
Web & HTTP JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Web & HTTP HTTP is a protocol that clients and servers use on the web to communicate. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
HTTP Request & Response HTTP Request is a packet of Information that one computer sends to another computer to communicate something Server Client HTTP Request HTTP Response HTTP Response is the packet of information sent by Server to the Client in response to an earlier Request made by Client JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Introduction to Servlets
What are Servlets? Robust & Scalable Creates Web Application Deployed to create Web Page Provides Interfaces & Classes Responds to any incoming requests Must be implemented to create Servlet JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
What are Servlets? Server Client Request Response is sent to client Response is generated at runtime JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Servlet Life Cycle Loading & Instantiation Start init() Initialized End of Request thread service() Handling Request destroy() End Stop JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Steps to create Simple Servlet 1 Create and compile simple servlet code 2 Add mappings to web.xml file 3 Start Apache Tomcat 4 Start Web Browser & Request Servlet JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Generic Servlet It has a very simple life cycle methods A generic servlet is a Generic Servlet is easier to write protocol independent Servlet that should always To write Generic Servlet you just need to extend javax.servlet.GenericServlet and override the service() method override the service() method to handle the client request.. Pros JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Servlet Classes & Interfaces Declares life cycle method of servlet Servlet Allows servlet to get Initialization methods ServletConfig Enables servlet to log access and access information ServletContext Used to read data from client request ServletRequest Used to write data to client response ServletResponse Implements servlet and Servlet.Config Interface GenericServlet Provides input stream to read requests from the client ServletInputStream Provides output stream to write responses to the client ServletOutputStream Indicates servlet error has occured ServletException Indicates servlet is not available UnavailableException Provides methods to handle Http Request and Response HttpServlet Enables servlets to read data from Http Request HttpServletRequest Enables servlets to write data to Http Response HttpServletResponse JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Session Tracking in Servlets Session tracking is a way to maintain state(data) of an user 3. Second new request 1. Request(new) 2. Response Client Server JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Hidden form field Cookies Http session URL rewriting JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Cookies in Servlet It is a small piece of information that is persisted between the multiple client requests 2. Request + Cookies 1. Request 3. Response + Cookies JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Useful Methods of Cookie Class Sets the maximum age of the cookies in seconds public void setMaxAge(int expiry) Returns the name of the cookie. Name cannot be changed after creation public String getName() Returns the value of the cookie public String getValue() Changes the name of the cookie public void setName(String name) Changes the value of the cookie public void setValue(String value) JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Creating & Deleting a Cookie 1.Cookie ck=new Cookie("user",“Edureka");//creating cookie object Creation 2.response.addCookie(ck);//adding cookie in the response 1.Cookie ck=new Cookie("user","");//deleting value of cookie 2.ck.setMaxAge(0);//changing the maximum age to 0 seconds 3.response.addCookie(ck);//adding cookie in the response Deletion JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Introduction to jsp
What is JSP? It is used to create web application just like Servlet technology. Also called as extension of servlet Portable Fast Development Powerful Tracking User Flexible Easy to maintain JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Advantages of JSP over Servlets JSP ▪ Extension to Servlet ▪ It is not a extension of JSP ▪ Easy to maintain ▪ Bit complicated ▪ No need to recompile and redeploy ▪ Code needs to be recompiled ▪ Less code than servlet ▪ More code comparatively Servlets Operation JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Life Cycle of JSP Buffer JSP (dynamic content) JSP Translator Servlet Object Servlet (.java File) JRE Compiler Class file JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Steps to create JSP Page 1 Create dynamic web project 2 Create JSP File 3 Start Apache Tomcat 4 Deploy the project and get the output JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Jsp Scripting & Directive elements
JSP Scripting Elements scriptlet <% java source code %> expression <%= statement %> declaration <%! field or method declaration %> JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Implicit Objects of JSP out Jspwriter request HttpServletrequest response HttpServletResponse config ServletConfig application ServletContext session HttpSession pageContent PageContext page Object exception Throwable JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
JSP Directive Elements <%@ page directive="value” %> Page directive Include directive <%@ include file="resourceName" %> Taglib directive <%@ taglib uri="uriofthetaglibrary" prefix="prefixoftaglibrary" %> JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Bean Class It is a reusable software component. A bean encapsulates many objects into one object, so we can access this object from multiple places. Moreover, it provides the easy maintenance. 1.<jsp:useBean id= "instanceName" scope= "page | request | session | application" 2.class= "packageName.className" type= "packageName.clas sName" 3.beanName="packageName.className | <%= expression >" > 4.</jsp:useBean> JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training