JSP from simple to deep (4) -- scriptlets

Source: Internet
Author: User
Tags date now

In the above tutorial, we have learned how to embed a Java expression between the <% = and %> character series in a JSP webpage. However, it is very difficult to do a lot of programming by placing Java expressions in HTML.

JSP also allows you to write JavaCodeBlocks are embedded in JSP. Specifically, place the Java code segment between the characters <% and %>. In fact, it is the same as the expression, but there is no equal sign at the beginning.

A code block is a well-known "scriptlet ". Scriptlet alone does not play any role in HTML. Every time the scriptlet contains the executed Java code, JSP is called.

The following code is the modified Code of the previous JSP tutorial. We added a scriptlet:

<HTML>

<Body>

<%

// This Is A scriptlet. notice that the "date"

// Variable we declare here is available in

// Embedded expression later on.

System. Out. println ("Evaluating date now ");

Java. util. Date = new java. util. Date ();

%>

Hello! The time is now <% = date %>

</Body>

</Html>

If you run the preceding example, you will notice that "system. Out. println" is output in the server log. This is a convenient method for some simple debugging. Some servers have the JSP debugging function in IDE. You can refer to the server documentation to check whether this function is available.

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.