servlets - part 3 - COP 4610L: Applications in the...

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

View Full Document Right Arrow Icon
COP 4610L: Servlets – Part 3 Page 1 Mark Llewellyn © COP 4610L: Applications in the Enterprise Fall 2006 Introduction to Servlet Technology– Part 3 COP 4610L: Applications in the Enterprise Fall 2006 Introduction to Servlet Technology– Part 3 School of Electrical Engineering and Computer Science University of Central Florida Instructor : Mark Llewellyn markl@cs.ucf.edu ENG3 236, 823-2790 http://www.cs.ucf.edu/courses/cop4610/fall2006
Background image of page 1

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

View Full DocumentRight Arrow Icon
COP 4610L: Servlets – Part 3 Page 2 Mark Llewellyn © Tomcat/Java Configuration - The Servlet API Your Tomcat installation includes the servlet-api.jar file. This file can be found in the /common/lib folder. Copy this file into your jdk/jre/lib/ext folder to allow the java compiler access to the javax.servlet package. Your Java set-up may already have this installed.
Background image of page 2
COP 4610L: Servlets – Part 3 Page 3 Mark Llewellyn © Tomcat/Java Configuration - The Servlet API You need this .jar file here to allow your Java environment to interface to the servlet container provided by Tomcat. You’ve already needed this file for Java to interface to a MySQL database. This will still be needed when our servlets access the database on the backend. You won’t have this folder unless you created it. This is my folder not Java’s.
Background image of page 3

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

View Full DocumentRight Arrow Icon
COP 4610L: Servlets – Part 3 Page 4 Mark Llewellyn © More XHTML Document Details Let’s look a bit closer at what happens in our servlet as it executes. (See the servlet code on page 23 of servlets-part 2 notes.) This line begins the overridden method doGet to respond to the get requests. In this case, the HttpServletRequest object parameter represents the client’s request and the HttpServletResponse object parameter represents the server’s response to the client. If method doGet is unable to handle a client’s request, it throws an exception of type javax.servlet.ServletException . If doGet encounters an error during stream processing (when reading from the client or writing to the client), it throws a java.io.IOException. protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
Background image of page 4
COP 4610L: Servlets – Part 3 Page 5 Mark Llewellyn © More XHTML Document Details (cont.) The first line above uses the response object’s setContentType method to specify the content type of the document to be sent as the response to the client. This enables the client browser to understand and handle the content it receives from the server. The content type is also referred to as the MIME (Multipurpose Internet Mail Extension) type of the data. In this servlet, the content type is text/html to indicate to the browser that the response is an XHTML document. The second line above uses the response object’s getWriter method to
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

servlets - part 3 - COP 4610L: Applications in the...

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

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