JSP (4)--Scriptlets

Source: Internet
Author: User
Tags date date now expression
JS above tutorial We have learned how to embed a Java expression between the <%= and%> character series in a JSP Web page. But it's hard to do a lot of programming work by putting Java expressions into HTML.

JSP also allows you to write Java code blocks embedded in the JSP. Place the Java code snippet between the <% and%> characters. It is the same as the expression, except that there is no equal sign at the beginning.

Code blocks are known as "Scriptlet". If it's just scriptlet, it doesn't work for HTML. And every time the scriptlet contains the Java code being executed, the JSP is invoked.

The following code is a modified code for the previous JSP tutorial, and we added a scriptlet:

<HTML>

<BODY>

<%

This is a scriptlet. Notice that "date"

Variable we declare here are available in the

Embedded expression later on.

SYSTEM.OUT.PRINTLN ("Evaluating date Now");

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

%>

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

</BODY>

</HTML>

If you run the above example, you will notice that the "System.out.println" output is in the server log. This is a convenient way to do some simple debugging. Some servers have the ability to debug JSP in the IDE, and you can see the server documentation to see if this functionality 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.