However, the expression language does not need to be considered, and if NULL, it is converted to an empty string of "";
<%@ page contenttype= "text/html" pageencoding= "GBK"%>
Three, expression language built-in objects
1.pageScope, Requestscope, Sessionscope, applicationscope built-in objects
Useful when you get properties that are set by built-in objects. This is to get the properties of page, request, session, application settings, such as:
Pagecontext.setattribute ("name", "Xiazdong");
Request.setattribute ("name", "Xiazdong");
${pagescope.name} can get the properties of the page;
${requestscope.name} can obtain the attributes of the request;
2.param and paramvalues built-in objects
Used to receive the incoming parameters;
PARAM.A similar to Request.getparameter ("a");
PARAMVALUES.A similar to Request.getparametervalues ("a");
If you want to get the value of the second A, pass ${paramvalues.a[1]};
3.pageContext built-in Objects
PageContext object can obtain Request,session,application object;
Pagecontext.request access to request built-in objects;
Pagecontext.session gets the session built-in object;
Pagecontext.application obtain Application object;
You can also invoke methods for JSP built-in objects: for example: (All are called by reflection)
(1) ${pagecontext.request.remoteaddr}; call Getremoteaddr ();
(2) ${pagecontext.session.new}; call IsNew () function
(3) ${pagecontext.session.id}; call GetID () function
Iv. expression Language for collections
We can use the expression language to facilitate the operation of the collection, such as:
(1)
list<integer> list = new arraylist<integer> ();
Request.setattribute ("A", list);
${a[0]} means to get the first element in the queue;
(2)
Map m = new HashMap ();
Request.setattribute ("Map", m);
${map["A"]} returns the value of Key=a;
${map.a} Returns the value of Key=a;
Example:
<%@ page contenttype= "text/html" pageencoding= "GBK" import= "java.util.*"%>
v. Expression language for MVC
The MVC design pattern is to pass the results to the JSP page through the servlet, and if you follow the general idea, you need to import the VO package into the JSP because you need to get the attributes through the Vo object;
Vo is the person class, then the JSP needs to be request.getattribute ("person") with person per = ("person"); Get the person object and then display it, from what you can see, we have to import the person class. However, JSP is best allowed to import only java.util.* packages;
If you are based on an expression language, you can write in the servlet:
Request.setattribute ("Vo", Vo object); Set properties, because RequestDispatcher is a server jump, so you can get results through ${VO. Properties} in the JSP, so you don't have to import VO packages;
The attribute of Vo can be invoked conveniently by means of an expression language;
Class a{
Private String A;
}
1. Passing a Vo object
A a1 = new A ();
Request.setattribute ("obj", A1);
${OBJ.A} obtains a property of the A1 object through reflection;
2. Passing multiple VO objects
List<a> as = new arraylist<a> ();
Request.setattribute ("as", as);
In the JSP page:
List as = (list) Request.getattribute ("as");
Iterator iter = As.iterator ();
while (Iter.hasnext ()) {
pagecontext.setattribute ("obj", Iter.next ());
${OBJ.A}//Call a property of Class A
}
Central:
(1) Receive list
(2) Putting each element into the PageContext attribute and displaying it through an expression language;
VI, operator
Expression-language support
+-*/% arithmetic operator;
= =,. =, >= and other comparison operators;
&&,. , | | such as logical operators;
。 :, empty and other special symbols;
Example:
Request.setattribute ("Num1", 20);
Request.setattribute ("num2", 30);
${NUM1-NUM2} represents a subtraction operation
${NUM1>=NUM2} represents a comparison operation
${Empty Num2} Indicates whether the decision is empty