the limitation of JavaBean in JSP
Gets the JavaBean property that must be instantiated
Forced type conversions
<% Employee employee = (employee) request.getattribute ("employee"); Computer comp = Employee.getcomputer (); String manufacturer = Comp.getmanufacturer ();%>
If the page is written with a logic error, it will cause code execution errors, and the JSP page will generate errors when compiling the page
Solutions
Use El expressions to simplify
What is El
El is expression Language (expressions language)
El's function
Replace complex code in a JSP page
El's Syntax
${EL Exprission}
${Bean.name} or ${bean[' name '}
${bean.name} is essentially the GetName () method that invokes the bean
Note: 1 el through. and [] to access data. For example ${applicationscope.user.username} or ${applicationscope.user["UserName"}
2 If the accessed property name contains some special symbols, such as "." or "-" such as non-alphanumeric or numeric symbols must be used []
3 applicationscope.user["User-name"]
4 If you use variables to pass in, you can only use []. For example
<%string Data="username";%>
${applicationscope.user[data]}
5 Of course there are four hidden objects: Applicationscope,sessionscope,requestscope,pagescope. With application, Session,request, PageContext corresponds to. For example, Applicationscope to get the value of a application range of properties
Automatic conversion type
An El can automatically convert a type when a data is obtained
More lenient restrictions on type
Easy to use
The EL application is simpler compared to embedding Java code in the JSP
El syntax
Start with "${" and End With "}"
Get the value directly using the variable name $
${Username}
Variable Property Scope name
Name in the property range El
Page Pagescope, for example ${pagescope.username}, indicates that a username variable is found in the page range and no return null
Request Requstscope
Session Sessionscope
Application Applicationscope
El operator
Operator "[]"
Operator "."
Role:
Get Object Properties
Gets the data in the collection of objects
A (list) collection is saved in session users
Simple application: Output name display
<%
Map names = new HashMap ();
Names.put ("One", "Liyang");
Names.put ("Both", "Wanghua");
Request.setattribute ("names", names);
%>
Name:${names.one}<br/>
Name: ${names["}<br/>"
An introduction to El Implicit objects
Object name Description
Pagescope Returns the variable name of the page range, which is mapped to the corresponding value
Requestscope Returns the name of the variable for the requested range, which is mapped to the corresponding value
Sessionscope Returns the variable name of the session scope, which is mapped to the corresponding value
Applicationscope Returns the variable in the applied range and maps the variable name to the corresponding value
param Returns the string value of the client's request parameter
Paramvalues Returns a set of values that map to the request parameters of the client
PageContext provides access to user requests and page information
Using El Expressions simplifies JSP page code, but what if you need to make a logical decision?
Click to view jstl Tag Library Introduction
The El expression and Jstl tag library use detailed