EL表达式的小结与简单例子

1、  EL表达式

1)   [] .

2)   算数操作符

3)   关系运算符

4)   Empty x

5)   三目运算

6)   隐含对象

pageContext  

pageScope

requestScope

sessionScope

applicationScope

param

paramValues

header[“User-Agent”]

headerValues    Map

cookie

initParam     

getInitParameter

例子:

package action;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ELServlet extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);



}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//传递引用
String a="abc";
String b="bcdk";
String c="ccddk";
request.getSession().setAttribute("obj1", b);
request.setAttribute("obj", a);
//传递list
ArrayList list=new ArrayList();
list.add(1);
list.add(2);
list.add(3);
request.setAttribute("list", list);
//传递map
Map m=new HashMap();
m.put("s", "ssss");
m.put("n", "nnnn");
request.setAttribute("m", m);
//Empty
String t1="";
String t2=null;
String t3="asdd";
Integer t4=0;
request.setAttribute("t1", t1);
request.setAttribute("t2", t2);
request.setAttribute("t3", t3);
request.setAttribute("t4", t4);

request.getRequestDispatcher("EL.jsp").forward(request, response);
}

}

Jsp:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


 
    EL表达式
 
   
    会全部找--- all:${obj}

   只在request的范围里面找---request:${requestScope.obj}

   只会在session的范围里面找----session:${sessionScope.obj1}

 

list传递


 list:${list}

 listItem:${list[0]}

 

把值打印出来:


 
 ${list}
 

 

map打印值


 map:${m}
 mapitem1:${m.s}
 mapitem2:${m['s'] }

 

算数运算:


 ${1+2}
 

关系运算:


 
  ${7+8}
 

 

Empty


 t1isEmpty:${empty t1}
 t2isEmpty:${empty t2}
 t3isEmpty:${empty t3}
 t4isEmpty:${empty t4}
 

param


 ======${param.name}
 ====${paramValues.check}
 


 

 

你可能感兴趣的:(javaWeb)