Java Web notes: JSP annotations, webjsp
Jsp comments
JSP supports two types of annotation syntax operations. One is explicit annotation, which is visible on the client and the other is implicit annotation, which is invisible on the client.
Explicit annotation Syntax: <! -- Comment content -->
Implicit annotation Syntax:
// Single row
/**/Multiple rows
<% -- JSP comment -- &>
Scriptlet
Scriptlet is important in jsp. All Java programs embedded in HTML code must be marked with scriptlet. There are three types of scriptlet code in JSP:
First: <%>
Type 2: <%! %>
Third: <% = %>
The first type of scriptlet is represented by <%>. In this scriptlet, you can define local variables and write statements as follows:
<% int x = 20; String info = "lunatictwo"; out.println("
Display result:
Method 2 scriptlet usage <%! %> Indicates that global variables, methods, and classes can be defined in this scriptlet, as shown below:
<%!public static final String INFO = "lunatictwo";%><%!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("
This program is in <%! The global constants, methods, and classes are defined in %>! No other statements appear in %>, so a common <%> output variable, call method, and output object is written.
Third: <% = %> the main function of the scriptlet is to output a variable or specific content, which is completed in the form of <% = %>, and sometimes called expression output.
<%int temp = 10;String INFO = "lunatictwo";%>
In actual development, try not to use out. println (); output instead of expression output. In this way, html code and java code are separated and only the variables generated by jsp are output.