Java Web notes: JSP annotations, webjsp

Source: Internet
Author: User

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.





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.