01.JSP Basic Syntax

Source: Internet
Author: User

First, JSP annotations and Scriptlet

1, JSP annotations

<!--This style of comment client can see-

<%

A single-line comment provided in Java that the client cannot see

Multiple lines of comments provided in/*java, which the client cannot see

*/

%>

<%--This annotation method The client also cannot see--%>

2, Scriptlet: Represents a Script applet, all Java programs embedded in HTML must be marked with scriptlet, altogether three ways of marking

<%%> In this scriptlet, you can write local variables, execute statements

<%!%> In this scriptlet, you can write global variables, classes, methods (variables are global)

<%=%>, used to output a variable or a specific content

First: Define local variables and execute statements

The second type: Write global variables, classes, methods

<%! Public Static FinalString info= "HAHA"; Public inta=10;//also a global variable%><%! Public intAddintXinty) {      returnx+y; }%><%!classperson{PrivateString name; Private intAge ;  PublicPerson (String name,intAge ) {            This. name=name;  This. age=Age ; }       PublicString toString () {return"Name:" + This. name+ "Age:" + This. Age; }   }%><%Out.println ("); Out.println ("//each refresh, a from plus oneOut.println ("); Out.println ("NewPerson ("Xiao Ming", "+") + ");%>

The third type, output a variable or a specific content

3, Out.println () and <%=%> output selection

. General selection in Web development <%=%> output as HTML language, such as output 10 rows and 10 columns below

<body><%    int rows=10;          int cols=10; %><table border= "1" width= "50%" ><% for    (int i=1;i<=rows;i++) {%>   <tr><%    for (int j=1;j<=cols;j++) {%>   <td><%=i*j%></td><%   } %>   </tr><%   }%></tabel></body>

This method is cumbersome and irregular, you should use the label to complete the display function

Ii. page directive

1, role: Define a JSP page related properties, including setting the MIME type, error page designation, file encoding, define the package that needs to be imported, if you import a SQL package, you can also make a connection to the database

2, Syntax: <% @page property = "Value"%>

Mime

Multi-purpose Internet Mail extension type, which tells the browser the type of multimedia in the message and enables the appropriate plug-in or application to read the file

When supported by the HTTP protocol, the browser recognizes data by using MIME data type information that is appended to the document. That is, when the output is transmitted to the browser, the browser must launch the appropriate application to process the output document. This can be done with multiple types of mime. In HTTP, MIME types are defined in the Content-type header.

Description: For file types that cannot be processed by the browser itself, the browser will allow the appropriate application to open the file in a way that the file is downloaded. If you want a JSP page to appear as a variant later, configure the appropriate MIME

3, File Encoding: CharSet used to set the file encoding, pageencoding can also set the file encoding. Pageencoding is present when the pageencoding code, otherwise according to CharSet encoding, does not exist, by default iso8859-1 encoding

4, error page settings

Description: When a page error occurs, the ErrorPage page is called, assuming that the errror.jsp iserrorpage must be set to True

But sometimes after the jump, the browser will think that error.jsp is also a wrong page, and then directly do not display, as follows left.

Solution, in error.jsp response browser tells the browser that this is the correct page

Note: The address bar does not change after the error, this address does not change the jump called server-side Jump

Error page centralized processing: Do not process each JSP file separately, want to concentrate on processing 404,500 and other errors, you need to modify the Web. XML configuration file

Third, including

1, contains the meaning: for the General page, contains the right figure four parts, where

The parts that change frequently are only concrete content. So you can talk about toolbars, page headers,

The end of the page is divided into four separate sections, which are then imported directly when the page is written.

OK. This makes it easy to modify, but also avoids the repetitive wheel build.

Includes static inclusions and dynamic inclusions

01.JSP Basic Syntax

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.