Scriptlet and annotation in JSP, and JSPscriptlet Annotation

Source: Internet
Author: User
Tags define local

Scriptlet and annotation in JSP, and JSPscriptlet Annotation

Scriptlet and comment in JSP.

Scriptlet:

In JSP, most of them are composed of Scriptlet. A script applet is embedded in html code and directly contains java code. There are three types of code:

<%> Define local variables and write the statement <%! %> Defines global variables. You can write a class or method <% = %> Expression output to output a variable or a specific value.

The first <%> Common Code is as follows:

         int i = 10 ;         int j = 20 ;         out.println(i * j) ;         out.println("
"+ (++ I) + "")

Type 2 <%! %> Is generally used to define global variables.

<%!         int i = 10 ;         int j = 20 ;%><%         out.println(i * j) ;         out.println("
"+ (++ I) +" "); %>

Note that java code and html are mixed,(out.println("

")

 

Third <% = %> example:

<%         int i = 10 ;%><%=i%><%="hello World!!!"%>

If you use too much in the program, the code will be very messy. Therefore, in the new version of jsp, A scriptlet tag is provided. Its syntax is as follows:


  
   
Java code
  ----------
String url = "www.baidu.com"; <%=url%> Notes in jsp:

Jsp supports two types of annotation syntax operations. One is display annotation, which can be seen by the client, and the other is implicit annotation, which cannot be seen by the client.

Display notes:
Implicit annotation:

// Single line comment/**/multi-line comment <%-comment-%>, jsp comment

For example:

 <% // Single line comment provided in Java. The client cannot see the multiline comment provided in/* Java, and the client cannot see */%> <% -- or -- %>'

Note:

In development, implicit annotation is not sent to the client. In jsp, try to replace out. println () with the expression output statement as much as possible ()

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.