JSP basic syntax a scriptlet

Source: Internet
Author: User
Tags define local

JSP as the foundation of web development, has its important position, so proficient in JSP grammar and application has become a top priority.

First we start with the basic syntax of JSP: (The following is from Li Xinghua Video manuscript collation)

Scriptlet Introduction

Script is a scripting applet, like the previous out.println () This statement is abbreviated in <%%>, it is obvious that the abbreviated sentence is a script.

The most important part of the JSP is the Scriptlet (script applet), all Java programs embedded in the HTML code must use the

Scriplet, there are three kinds of scriplet code in JSP

The first kind: <%%>, in this scriplet can define local variables, write statements;

The second type: <%! %>, in this scriplet can define global variables, methods, classes;

The third type: <% =%>, for outputting a face or a specific content.

The first kind of script<%%>

 

To insert pure Java code into a JSP page in <%%>

The second kind of script<%!%>

The main function is to define the global variables, methods, classes, and assume the following definitions of methods and classes to validate

<%!    
      public static final String info= "www.baidu.com";    
 %>    
 <%!    
       public int Add (int x,int y) {return    
         x+y;    
      }    
 %>    
 <%!    
     Class person{    
       private String name;    
       private int age;    
       Public person (String Name,int age) {    
           this.name=name;    
           this.age=age;     
       }    
       Public String toString () {return    
           "name=" +this.name+ "; age=" +    
               this.age;    
       }    
    }    
 %>    
 <%    
        out.println ("

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.