How to write Java code in JSP

Source: Internet
Author: User

differenceJSP and HTML, the most significant advantage is that the JSP can be written in Java code, but not in HTML. ---------------------------

Writing

<%! %>, which can declare a variable or method, note: The variables declared here are global

<%%> Compared to the method above, the local

<%=%>, used to output expressions to the browser, note: This expression cannot be followed by a semicolon

---------------------------------------------------

Three directives are defined in jsp2.0: page directive, include directive, taglib directive.

1. The most common thing we have seen about page directives is this:

<% @page contenttype= "text/html;charset=gb2312" import= "Java.util.Date"%>

Mainly used to: set the encoding, import the jar package

2. With regard to the include directive, which he used to introduce other JSP pages, the JSP engine translates two jsps into a servlet, so also called static ingestion

3. With regard to the TAGLIB directive, it is a prefix that defines a tag library and its custom tags. For example, the use of C:foreach used by us. Import the JSTL package first, then add this tag to the JSP: <%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%> you can use C:foreach

How to write Java code in JSP

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.