servlets - part 3

servlets - part 3 - CNT 4714: Enterprise Computing Spring...

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

View Full Document Right Arrow Icon
CNT 4714: Servlets – Part 3 Page 1 Dr. Mark Llewellyn © CNT 4714: Enterprise Computing Spring 2011 Introduction to Servlet Technology– Part 3 Department of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cnt4714/spr2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
CNT 4714: Servlets – Part 3 Page 2 Dr. Mark Llewellyn © Tomcat/Java Configuration - The Servlet API Your Tomcat installation includes the servlet-api.jar file. This file can be found in the lib folder in Tomcat. Copy this file into your jdk/jre/lib/ext folder to allow the java compiler access to the javax.servlet package. Note that your Java set-up may already have this installed depending on several things, so check your jdk/jre/lib/ext folder first.
Background image of page 2
CNT 4714: Servlets – Part 3 Page 3 Dr. 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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
CNT 4714: Servlets – Part 3 Page 4 Dr. 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 22 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
Page 5 Dr. 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 obtain a reference to the PrintWriter object that enables the servlet to send content to the client. If the response is binary data, like an image, method getOutputStream would be used to obtain a reference to a ServletOutputStream object.
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 / 31

servlets - part 3 - CNT 4714: Enterprise Computing Spring...

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