Java Servlets - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Java Servlets

Description:

IOException, ServletException ... IOException. java.io. PrintWriter. javax.servlet.http ... import java.io.IOException; import javax.servlet.ServletException; ... – PowerPoint PPT presentation

Number of Views:59
Avg rating:3.0/5.0
Slides: 9
Provided by: julie387
Category:

less

Transcript and Presenter's Notes

Title: Java Servlets


1
Java Servlets
  • A servlet is just a Java class that runs on a
    server
  • A servlet (for a web application) extends the
    HttpServlet abstract class
  • public class ServletClassName extends HttpServlet
  • // code here

2
Java Servlets
  • The servlet is part of a package
  • ? we need to include a package statement at the
    beginning of the file for the servlet class
  • Code inside the Java class is Java code
  • No special tags like in a JSP
  • ? we need to import the appropriate classes

3
Java Servlets classes to import
  • Typically, we need to import the following
    classes
  • HttpServlet
  • HttpServletRequest
  • // JSP remember the implicit object request
  • HttpServletResponse
  • // JSP remember the implicit object response
  • .

4
Java Servlets classes to import
  • PrintWriter
  • // JSP remember the implicit object out
  • IOException, ServletException
  • / Some methods (which we will override) of the
    HttpServlet class throw these two exceptions /

5
Java Servlets Classes to import
6
Java Servlets
  • package packageName
  • import javax.servlet.http.Servlet
  • import javax.servlet.http.HttpServletRequest
  • import javax.servlet.http.HttpServletResponse
  • import java.io.PrintWriter
  • import java.io.IOException
  • import javax.servlet.ServletException
  • // other import statements as necessary
  • public class ServletClassName extends HttpServlet
  • // code here

7
Java Servlets
  • package packageName
  • // Using bulk import statements
  • import javax.servlet.http.
  • import java.io.
  • import javax.servlet.ServletException
  • // other import statements as necessary
  • public class ServletClassName extends HttpServlet
  • // code here

8
Java Servlets
  • Our servlet extends the abstract class
    HttpServlet (javax.servlet.http package)
  • HttpServlet extends the abstract class
    GenericServlet (javax.servlet package)
  • GenericServlet extends Object (java.lang package)
  • ? A number of methods are inherited from these
    classes by our servlet class
Write a Comment
User Comments (0)
About PowerShow.com