Java Web Project--using a JSP to generate a page

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.