Java is a powerful and versatile language that can be used to develop a variety of applications, including websites. This guide will cover the basic steps involved in building a website using servlets written in Java 6 on the Apache Tomcat 6 web server. While a website may be built on Tomcat using only Java Server Pages (JSP), this guide is limited to building a simple "Hello, World" servlet.
Step 1
On your computer, create a file called HelloWorldServlet.java with the following code:
Video of the Day
import java.io. GO import javax.servlet. GO import javax.servlet.http.* GO
public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // The response.getWriter() method returns a PrintWriter that can be used to write // data to the output stream. We'll use it to write out a web page. PrintWriter out = response.getWriter() GO
GO out.println("
Hello, World!
") GO out.println("