Servlet Tutorial Pdf

Tutorial

What Is Servlet

What is a web application? How can we develop one in Java? Learn Servlet Technology for developing Web applications in Java.

Author: Deron Eriksson
Description: This tutorial describes how to serve up a PDF from a servlet.
  • Servlet: Introduction to Web. Web consists of billions of clients and server connected through wires and wireless networks. The web clients make requests to web server. The web server receives the request, finds the resources and return the response to the client. When a server answers a request, it usually sends some type of content to the client.
  • Although HTML is the most common kind of document that servlets create, it is not unusual for servlets to create other document types. For example, it is quite com-mon to use servlets to generate Excel spreadsheets (content type application/ vnd.ms-excel—see Section 7.3), JPEG images (content type image/jpeg—see.
Servlet Tutorial Pdf
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0) || Tomcat 5.5.20

It's possible to have a servletW serve up PDF content by specifying the content type of the servlet response to be the 'application/pdf' MIME type via response.setContentType('application/pdf'). This tutorial will demonstrate this using a project with the following structure.

The TestServlet class is mapped to /test. When the TestServlet is hit by a browser request, it locates the pdf-test.pdf file in the web directory. It sets the response content type to be 'application/pdf', specifies that the response is an attachment, and sets the response content length. Following that, it writes the contents of the PDF file to the response output stream.

TestServlet.java

(Continued on page 2)

Page: 1 2>

Java Servlet Tutorial Pdf

Java servlet tutorial for beginners

Related Tutorials:

  • Eclipse :: How do I debug my web project in Tomcat from Eclipse?
  • Files :: How do I write to a PDF file using iText?