servlets - part 5 - 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 5 Page 1 Mark Llewellyn © COP 4610L: Applications in the Enterprise Fall 2006 Introduction to Servlet Technology– Part 5 COP 4610L: Applications in the Enterprise Fall 2006 Introduction to Servlet Technology– Part 5 School of Electrical Engineering and Computer Science University of Central Florida Instructor : Mark Llewellyn [email protected] ENG3 2362, 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 5 Page 2 Mark Llewellyn © Servlets That Return Content Other Than Text/HTML The servlets that we have seen so far have all returned content which was text-based. Thus all of the servlets contained the following line of code: response.setContentType("text/html"); The Content-Type response header gives the MIME (Multipurpose Internet Mail Extension) type of the response document. Setting the value of this header is so common that the special method setContentType in HttpServletResponse was created. MIME types are of the format maintype/subtype for officially registered types. There are many officially registered types, some of which are shown in the table on the next page. The officially registered types can be found at http://www.iana.org/assignments/media-types/index.html
Background image of page 2
COP 4610L: Servlets – Part 5 Page 3 Mark Llewellyn © Some Common MIME Types XML document text/xml HTML document text/html JPEG image GIF image MIDI sound file Zip archive Java bytecode (.class) file Powerpoint presentation Excel spreadsheet JAR file Acrobat (.pdf) file Meaning image/jpeg image/gif audio/midi application/zip application/x-java-vm application/vnd.ms-powerpoint application/vnd.ms-excel application/jar application/pdf Type
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 5 Page 4 Mark Llewellyn © Example Servlet That Returns An Excel Spreadsheet I’ve put an example on the code page for the class (you can run it directly, but I did not put a reference to it on the servlet index page) of a servlet that returns an Excel spreadsheet to the client. I made this servlet very simple and it simply generates the Excel spreadsheet contents and returns it to the client. The servlet code is shown on the next page and the Excel spreadsheet that is returned is shown on the following page. Note that this servlet contains the following line of code: response.setContentType("application/vnd.ms-excel "); To execute the servlet type: http://localhost:8080/cop4610/spreadsheet
Background image of page 4
Page 5 Mark Llewellyn © ApplesAndOranges Servlet //Servlet that returns an Excel spreadsheet //Spreadsheet compares apples and oranges!! import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ApplesAndOranges extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/vnd.ms-excel"); PrintWriter out = response.getWriter(); out.println("\tQ1\tQ2\tQ3\tQ4\tTotal");
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.

This note was uploaded on 07/14/2011 for the course COP 4610L taught by Professor Staff during the Spring '09 term at University of Central Florida.

Page1 / 23

servlets - part 5 - 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