How to Run a JSP Program in Apache Tomcat (Linux)

See Apache: Tips and Tricks for similar articles.

A Java Server Page, or JSP, program is a crucial part of a Java web application because the JSP will send a response back to the server in the form of a web page. For example, a JSP might display the line items of an order to the browser user. In this topic, you will create a very simple JSP and learn how to run the program at the Tomcat server.

To learn how to run a JSP in Apache Tomcat in a Linux environment, follow these 7 steps:

  1. In your text editor, you will develop a simple JSP that creates a web page to display the current date. Type in the following statements in a new file:
    
    <%@ page language="java" contentType="text/html"%>
    <%@ page import="java.text.*,java.util.*" %>
    <html>
    <head>
    <title>Date JSP</title>
    </head>
    <% SimpleDateFormat sdf=new SimpleDateFormat("MM/dd/yyyy"); %>
    <body>
    <h1>Welcome to Tomcat! Today is </h1>
    </body>
    </html>
    
    The program contains <%@ tags that provide metadata about the JSP and import directives. The JSP also contains HTML tags that will be rendered by the browser in the usual way. Note the <% tags that encapsulate Java code. The snippets of Java code are referred to as "scriplets." When the JSP is requested by the browser, the program will be converted into a servlet by a program in the Tomcat container (Jasper) and the HTML output will be sent to the browser.
  2. Save your file as DateJSP.jsp.
  3. Copy your file to CATALINA_BASE/webapps/ROOT, e.g., /var/lib/tomcat7/webapps/ROOT.
  4. Start the Tomcat server.
  5. Start your browser if it is not already running.
  6. In the address area of the browser, type http://localhost:8080/DateJSP.jsp and submit that address to the browser.
  7. The output of your JSP page will be displayed: Date JSP

Related Articles

  1. How to Start and Stop Apache Tomcat from the Command Line (Windows)
  2. How to Deploy a WAR File to Apache Tomcat (Windows)
  3. How to Start and Stop Apache Tomcat from the Command Line (Linux)
  4. How to Deploy a WAR File to Apache Tomcat (Linux)
  5. How to Run a JSP Program in Apache Tomcat (Windows)
  6. How to Check the Status of the Apache Tomcat Server (Windows)
  7. How to Deploy a Web Application Using the Apache Tomcat Manager (Windows)
  8. How to Check the Status of the Apache Tomcat Server (Linux)
  9. How to Set Default Context Path in Apache Tomcat (Windows)
  10. How to Use the autoDeploy Attribute in Apache Tomcat (Windows)
  11. How to Deploy a Web Application Using the Apache Tomcat Manager (Linux)
  12. How to List Deployed Applications Using the Apache Tomcat Manager (Windows)
  13. How to Run Multiple Instances of Apache Tomcat on One Server (Windows)
  14. How to Run a JSP Program in Apache Tomcat (Linux) (this article)
  15. How to Establish a JDBC Connection in Apache Tomcat (Windows)
  16. How to Verify Apache Tomcat Server Operation (Windows)
  17. How to Cluster in Apache Tomcat (Linux)
  18. How to Undeploy Web Applications Using the Apache Tomcat Manager (Windows)
  19. How to Set Default Context Path in Apache Tomcat (Linux)
  20. How to Use the Java Logging API in Apache Tomcat (Windows)
  21. How to Cluster in Apache Tomcat (Windows)
  22. How to Use the Java Logging API in Apache Tomcat (Linux)
  23. How to Use the autoDeploy Attribute in Apache Tomcat (Linux)
  24. How to Configure Apache Tomcat to Use MBeans (Windows)
  25. How to List Deployed Applications Using the Apache Tomcat Manager (Linux)
  26. How to Install and Configure Apache Tomcat (Windows)
  27. How to Configure Apache Tomcat to Use MBeans (Linux)