LectureSet4-JSP-Servlets Lec

LectureSet4-JSP-Servlets Lec - Servlet/JSP ServletsandJSPs

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Servlet/JSP
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Servlets and JSPs 2 The purpose of a servlet is to create a Web page in  response to a client request Servlets are written in  Java , with a little HTML mixed in The HTML is enclosed in  out.println( )  statements JSP  ( Java Server Pages ) is an alternate way of creating  servlets JSP is written as ordinary  HTML , with a little  Java  mixed in The Java is enclosed in special tags, such as  <% . .. %> The HTML is known as the template text JSP files must have the extension  .jsp JSP is  translated  into a Java servlet, which is then  compiled Servlets are run in the usual way The browser or other client sees only the resultant HTML, as  usual Tomcat knows how to handle servlets and JSP pages
Background image of page 2
A “Hello World” servlet (from the Tomcat installation documentation) 3 public class HelloServlet extends HttpServlet {   public void doGet(HttpServletRequest request,                               HttpServletResponse response)        throws ServletException, IOException {     response.setContentType("text/html");     PrintWriter out = response.getWriter(); out.println(docType +                 "<HTML>\n" +                 "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +                 "<BODY BGCOLOR=\"#FDF5E6\">\n" +                 "<H1>Hello World</H1>\n" +                 "</BODY></HTML>");   } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Servlets An alternate form of server-side computation that  uses Java The Web server is extended to support an API,  and then Java programs use the API to create  dynamic web pages Using Java servlets provides a platform- independent replacement for CGI scripts.  Servlets can be embedded in many different  servers because the servlet API, which you use  to write servlets, assumes nothing about the  server's environment or protocol.  
Background image of page 4
The Advantages of Servlets Over Traditional  CGI Efficiency CGI invoking   Overhead of starting a new process can dominate the  execution time. For N simultaneous request, the same code is loaded into  memory N times. When terminated, lose cache computation, DB connection  . Servlet  JVM stays running and handles each request using Java  thread. Only a single copy is loaded into memory Straightforward to store data between requests
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Advantages of Servlets Over Traditional  CGI Convinient CGI invoking   Easy to install and setup Servlet  Provides an extensive infrastructure for automatically  parsing and decoding HTML form data, reading and setting  HTTP headers, handling cookies, tracking sessions and 
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

LectureSet4-JSP-Servlets Lec - Servlet/JSP ServletsandJSPs

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online