2. JSP script

Source: Internet
Author: User

JSP script

JSP scripts contain JSP expressions, declarative identities, and scripting programs. With these identities, you can declare variables, define methods, and perform operations on various expressions in a JSP page as if you were writing a Java program

1. Application of code snippets in JSP

  Syntax format: <% java code or script code%>

Code snippets are more flexible to use, either as Java code or as built-in objects provided by JSPs

For example:

  

    <%         int num=1;          for (int i=1;i<=10;i++) {            num*=i;        }        Out.println (the factorial of "10 is:" +num)     ; %>

2. Using JSP expressions

A JSP expression is used to output information in a page, which can be inserted into the text of a Web page for output text content or inserted into HTML tags to dynamically set property values

  JSP expression Syntax format: <%= expression%>

  

    <%         Stringname="Admin"; StringPhoto="1.jpg"; %>User name:<%=name%>Photos<imgsrc= "<%=photo%>">

Note: You cannot have spaces before% and =

3. Declaration of Identity

You can also define member variables and member methods in a JSP page as you would write a Java file, which declares the identity of the application. Defining a variable or method in a JSP page with a claim identity is global.

Syntax format: <%! Declaration order or method%>

Because the variable that declares the identity is global, there is a thread-safety problem when multiple users are concurrently accessing it, and this approach applies very little

  

    <%!        int count=0;          Public int GetCount () {            return + +count        ;     } %>          You are <%=getcount ()%> Visitors

2. JSP script

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.