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:
<%@ 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 <%= sdf.format(new Date()) %></h1> </body> </html>
<%@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.
http://localhost:8080/DateJSP.jspand submit that address to the browser.