JSP Learning Note II: The scripting syntax of JSP syntax

Source: Internet
Author: User

1. Script segment: <% ...%>

2. Expression: <%=. %>

Below, let's give an example to illustrate.

The JSP code is as follows:

<%    int  =ten; %> <% = a %>    

The corresponding translation file, corresponding to the following code:

int a = 10;out.print (a);

As you can see, the expression corresponds to the output statement. Therefore, written <%=a;%> is equivalent to Out.print (A;);

3. Disclaimer: <%! ...%>

We write the following statement in the JSP code:

 

<% !     int  =+; %>

The corresponding translation file, the corresponding code is declared in the Class A member variable

int h = 30;

So, can we declare a class?

Below, let's try to modify the code as follows:

  

<%test ();%><%! inth=  -; void Test () {System.out.println (H* 3); }%>

As you can see, the call to the test () function is no problem, save the Refresh page, and see that the output of the console is 90, so declaring the function is possible.

The corresponding translation file can be seen, declares the function, and calls the method in the service class:

    int h = +;        void Test () {        System.out.println (H * 3);    }    

...

Test ();

JSP Learning Note II: The scripting syntax of JSP syntax

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.