We used a servlet to generate a Web page, but we can see that using a servlet to generate a Web page must embed the contents of the Web page into the Java code, not very convenient.
So is there any way to embed Java code in HTML code instead of embedding HTML code into Java code like a servlet does? The answer is to use JSP.
JSP is a piece of Java code embedded in HTML that is similar to "<%%>".
Below we will show the effect of displaying a Web page using a JSP page.
The JSP page begins with a line of "<%@ page contenttype=" Text/html;charset=utf-8 "%>" to make the JSP page type, encoding, and so on.
Create a new JSP file page3.jsp under the WebContent directory. The code in which to add a period of output date.
Page3.jsp content is as follows:
<%@page Import="java.util.Date"%><%@page Import="Java.io.PrintWriter"%><%@ Page Language="Java"ContentType="text/html; charset=iso-8859-1"pageencoding="iso-8859-1"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=iso-8859-1"><title>Page3</title></Head><Body><% //PrintWriter out=Response.getwriter (); Out.println (New Date());%></Body></HTML>
Starting the server, you can see the current time information displayed in the HTTP://LOCALHOST:8080/WEBPROJECT/PAGE3.JSP Web page as follows:
Java Web Project--using a JSP to generate a page