Writing Your First Servlet

Writing Your First Servlet - Writing Your First Servlet...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Writing Your First Servlet Change the Classpath >> Important << Before you do anything, make sure the compiler will be able to find the servlet.jar file. The servlet.jar file contains Java Web Server's implementation of the Servlet API. There are two ways to achieve this: 1. change the classpath in your system settings permanently. This option is highly recommended since it will apply in the future when you want to compile your servlet. Write the servlet Start your favorite file editor. Then type or copy the code listing below: //Import needed Java packages import java.io.*; import javax.servlet.*; import javax.servlet.http.*; // Create a class which inherits from GenericServlet or HttpServlet. public class MyFirstServlet extends HttpServlet { /** * Override the service method. * Here we handle the HTTP GET method by building a simple web * page. */ public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out; String title = "MyFirst Servlet Output"; // set content type and other response header fields first response.setContentType("text/html"); // then write the data of the response out = response.getWriter();out = response....
View Full Document

This note was uploaded on 07/15/2011 for the course ECO 2023 taught by Professor Mr.raza during the Summer '10 term at FAU.

Page1 / 5

Writing Your First Servlet - Writing Your First Servlet...

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

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