JSP compilation error of the sinkhole

Source: Internet
Author: User

Situation: Write your own small website today, use Jsp+servlet+mysql,bean,dbutil,dao and so have already written, MySQL also already created good database, table, and field, add complete data, start Tomcat, result error:

Error process: System.out.println () in a number of key areas;

Think of the solution, the last man pointing, just think that the JSP el expression needs to operate according to get (), set () method, so, the error reason is: Get (), set () method naming is not standardized, resulting in El Unrecognized, unable to operate, error;

EL: {

First, the JSP El language definition

E L (Expression Language) Purpose: In order to make JSP is easier to write.

The expression language is inspired by the ECMAScript and XPath expression languages, which provide a way to simplify expressions in the JSP. It is a simple language based on the available namespaces (PageContext property), nested properties, and accessors for collections, operators (arithmetic, relational, and logical), extensible functions that map to static methods in Java classes, and a set of implicit objects.

EL provides the ability to use run-time expressions outside of the scope of the JSP scripting element. Scripting elements are elements in a page that can be used to embed Java code in a JSP file. They are typically used for object manipulation and for performing calculations that affect what is generated. JSP 2.0 adds an EL expression as a scripting element.

ii. introduction of JSP El

1. Grammatical structure
${expression}
2, [] and. Operators
EL provides "." and "[]" operators to access data.
When the name of the property to be accessed contains some special characters, such as. or? Other than letters or numbers, be sure to use "[]". For example:
${user. My-name} should be changed to ${user["My-name"}
If you want to dynamically fetch values, you can do it with "[]" and "." cannot be dynamically evaluated. For example:
${sessionscope.user[data]} in data is a variable
3. Variables
The EL Access variable data method is simple, for example: ${username}. It means to take out a variable whose name is username in a range.
Because we do not specify a range of username, it will be searched sequentially from page, Request, Session, application range.
If the way to find username, direct callback, no longer continue to find, but if all the scope is not found, the return null.
Name of the attribute range in El
Page Pagescope
Request Requestscope
Session Sessionscope
Application Applicationscope

ii. valid expressions in JSP EL

Valid expressions can contain literals, operators, variables (object references), and function calls. We will look at each of these valid expressions separately:

1. Text

The JSP expression language defines the following text that can be used in an expression:

text The value of the literal

Boolean

True and False

Integer

Similar to Java. Can contain any positive or negative numbers, such as 24,-45, 567

Floating point

Similar to Java. Can contain any positive or negative floating-point numbers, such as -1.8E-45, 4.567

String

Any string that is qualified by single or double quotation marks. For single quotes, double quotes, and backslashes, use a backslash character as an escape sequence. It is important to note that single quotes do not need to be escaped if double quotes are used at both ends of the string.

Null Null

2. Operator

The JSP expression language provides the following operators, most of which are common operators in Java:

Terminology definition

Arithmetic type

+,-(two Yuan), *,/, Div,%, mod,-(one yuan)

Logic type

And, &&, or, | | 、!、 not

Relationship Type

= =, EQ,! =, NE, GT, <=, le, >=, GE. Can be compared with other values, or with Boolean, String, Integer, or floating-point literals.

Empty

An empty operator is a prefix operation that can be used to determine whether a value is empty.

Conditional type A? B:c. Assigns a value B or C according to the result of a assignment.

3. Implicit Objects

The JSP expression language defines a set of implicit objects, many of which are available in JSP Scriplet and expressions:

PageContext

The context of the JSP page. It can be used to access JSP implicit objects such as requests, responses, sessions, outputs, ServletContext, and so on. For example, ${pagecontext.response} assigns a value to a page's response object.

In addition, several implicit objects are available that allow easy access to the following objects:

Terminology Definition

Param

Maps the request parameter name to a single string parameter value (obtained by calling Servletrequest.getparameter (string name). The GetParameter (String) method returns a parameter with a specific name. An expression of $ (param.name) is equivalent to Request.getparameter (name).

Paramvalues

Map the request parameter name to a numeric array (obtained by calling Servletrequest.getparameter (String name). It is very similar to the Param implicit object, but it retrieves an array of strings instead of a single value. Expression ${paramvalues.name) is equivalent to Request.getparamtervalues (name).

Header

Map the request header name to a single string header value (obtained by calling Servletrequest.getheader (string name). The expression ${header.name} is equivalent to Request.getheader (name).

Headervalues

Map the request header name to a numeric array (obtained by calling Servletrequest.getheaders (String)). It is very similar to an implicit object. The expression ${headervalues.name} is equivalent to Request.getheadervalues (name).

Cookies Maps the cookie name to a single Cookie object. A client request to the server can obtain one or more cookies. Expression ${cookie.name.value} returns the first cookie value with a specific name. If the request contains more than one cookie with the same name, the ${headervalues.name} expression should be used.
Initparam The context initialization parameter name is mapped to a single value (obtained by calling Servletcontext.getinitparameter (String name).

In addition to the above two types of implicit objects, there are also objects that allow access to a wide range of variables, such as Web contexts, sessions, requests, and pages:

Terminology Definition

Pagescope

Maps the variable name of a page range to its value. For example, an EL expression can use ${pagescope.objectname} to access a page-scoped object in a JSP, and you can use ${pagescope.objectname.attributename} to access the properties of an object.

Requestscope

Map the variable name of the request scope to its value. The object allows access to the properties of the requested object. For example, an EL expression can use ${requestscope.objectname} to access an object of a JSP request scope, and you can use ${requestscope.objectname.attributename} to access the properties of an object.

Sessionscope

Maps a session-scoped variable name to its value. The object allows access to the properties of the session object. For example:


$sessionScope. Name}

Applicationscope

Maps application-scoped variable names to their values. The implicit object allows access to application-scoped objects.

third, special emphasis:

1. Note that when an expression references one of these objects by name, the corresponding object is returned instead of the corresponding property. For example, if an existing PageContext property contains some other value, ${pagecontext} also returns the PageContext object.

2, note <%@ page iselignored= "True"%> indicates whether the El language is disabled, true to suppress. False indicates that the. JSP2.0 enabled El language is not suppressed.

Iv. Illustrative examples

1. For example,

<%=request.getparameter ("username")% > equivalent to ${param.username}

2, for example, but the following El language can be completed if a username is empty, null is not displayed, but the value is not displayed.

<%=user.getaddr ()%> is equivalent to ${user.addr }.

3. For example:

<% =request.getattribute ("userlist")%> equivalent to $ {requestscope.userlist}

4, for example, the principle is as above example 3.

${Sessionscope.userlist} 1

${Sessionscope.userlist} 2

${Applicationscope.userlist} 3

${Pagescope.userlist} 4

${uselist} Meaning: The order of execution is 4 1 2 3.

“.” The following is just a string, not a real built-in object, not a call to an object.

4. For example,

<%=USER.GETADDR ()%> equivalent to ${user.addr}

The first sentence is preceded by the user, which is a variable.

After the second sentence, the user must be a property in a range.

}

Summary :1. Never use the "_" Underline in the attribute name of the JavaBean; (can be in an SQL statement)

2. In the Get (); Set () method, the first letter is capitalized;

JSP compilation error of the sinkhole

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.