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