Servlets part 5 - CNT 4714 Enterprise Computing Spring 2011 Introduction to Servlet Technology Part 5 Instructor Dr Mark Llewellyn [email protected]

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

View Full Document Right Arrow Icon
CNT 4714: Servlets – Part 5 Page 1 Dr. Mark Llewellyn © CNT 4714: Enterprise Computing Spring 2011 Introduction to Servlet Technology– Part 5 Department of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn [email protected] 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 5 Page 2 Dr. 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
CNT 4714: Servlets – Part 5 Page 3 Dr. Mark Llewellyn © Some Common MIME Types Type Meaning application/pdf Acrobat (.pdf) file application/jar JAR file application/vnd.ms-excel Excel spreadsheet application/vnd.ms-powerpoint Powerpoint presentation application/x-java-vm Java bytecode (.class) file application/zip Zip archive audio/midi MIDI sound file image/gif GIF image image/jpeg JPEG image text/html HTML document text/xml XML document
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 5 Page 4 Dr. 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/CNT4714/spreadsheet
Background image of page 4
CNT 4714: Servlets – Part 5 Page 5 Dr. 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"); out.println("Apples\t78\t87\t92\t29\t=SUM(B2:E2)"); out.println("Oranges\t77\t86\t93\t30\t=SUM(B3:E3)"); } }
Background image of page 5

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

View Full DocumentRight Arrow Icon
CNT 4714: Servlets – Part 5 Page 6 Dr. Mark Llewellyn © Response From ApplesAndOranges Servlet
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.

This note was uploaded on 07/14/2011 for the course CNT 4714 taught by Professor Llewellyn during the Spring '10 term at University of Central Florida.

Page1 / 24

Servlets part 5 - CNT 4714 Enterprise Computing Spring 2011 Introduction to Servlet Technology Part 5 Instructor Dr Mark Llewellyn [email protected]

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