使用servlet或框架,在后台设置数据,内容如下:
  这里我设置了多种数据类型,要都放在request里面。
//普通字符串
request.setAttribute("hello", "hello world");  
//结构
Group group = new Group();
group.setName("中国");  
User user = new User();
user.setUsername("java小强");
user.setAge(18);
user.setGroup(group);  
request.setAttribute("user", user);  
//map
Map mapValue  = new HashMap();
mapValue.put("key1", "value1");
mapValue.put("key2", "value2");
request.setAttribute("mapvalue", mapValue);  
//字符串数组
String[] strArray = new String[]{"a", "b", "c"};
request.setAttribute("strarray", strArray);  
User[] users = new User[10];
for (int i=0; i<10; i++) {
 User u = new User();
 u.setUsername("U_" + i);
 users[i] = u;
}
request.setAttribute("users", users); 
//List集合
List userList = new ArrayList();
for (int i=0; i<10; i++) {
 User uu = new User();
 uu.setUsername("UU_" + i);
 userList.add(uu);
}
request.setAttribute("userlist", userList);  
//测试empty
request.setAttribute("value1", null);
request.setAttribute("value2", "");
request.setAttribute("value3", new ArrayList());
request.setAttribute("value4", "123456"); 
return mapping.findForward("success");  
  跳转到JSP页面,使用EL表达式进行数据的输出或计算工作:
  前台使用EL取出数据代码:
    
        
            01 | 
            <body><h1>测试EL表达式</h1><br> | 
        
    
 
    
        
            02 | 
            <hr><li>普通字符串</li><br> | 
        
    
 
    
        
            03 | 
            hello(jsp脚本):<%=request.getAttribute("hello") %><br> | 
        
    
 
    
        
            04 | 
            hello(el表达式,el表达式的使用方法$和{}):${hello }<br> | 
        
    
 
    
        
            05 | 
            hello(el表达式,el的隐含对象pageScope,requestScope,sessionScope,applicationScope,<br>  | 
        
    
 
    
        
            06 | 
            如果未指定scope,它的搜索顺序为pageScope~applicationScope):${requestScope.hello }<br> | 
        
    
 
    
        
            07 | 
            hello(el表达式,scope=session):${sessionScope.hello }<br> | 
        
    
 
    
        
            08 | 
            <p><li>结构,采用.进行导航,也称存取器</li><br> | 
        
    
 
    
        
            09 | 
            姓名:${user.username }<br> | 
        
    
 
    
        
            11 | 
            所属组:${user.group.name }<br> | 
        
    
 
    
        
            12 | 
            <p><li>输出map,采用.进行导航,也称存取器</li><br> | 
        
    
 
    
        
            13 | 
            mapvalue.key1:${mapvalue.key1 }<br> | 
        
    
 
    
        
            14 | 
            mapvalue.key2:${mapvalue.key2 }<br> | 
        
    
 
    
        
            15 | 
            <p><li>输出数组,采用[]和下标</li><br> | 
        
    
 
    
        
            16 | 
            strarray[2]:${strarray[1] }<br> | 
        
    
 
    
        
            17 | 
            <p><li>输出对象数组,采用[]和下标</li><br> | 
        
    
 
    
        
            18 | 
            userarray[3].username:${users[2].username }<br> | 
        
    
 
    
        
            19 | 
            <p><li>输出list,采用[]和下标</li><br> | 
        
    
 
    
        
            20 | 
            userlist[5].username:${userlist[4].username }<br> | 
        
    
 
    
        
            21 | 
            <p><li>el表达式对运算符的支持</li><br> | 
        
    
 
    
        
            24 | 
            10 div 5=${10 div 5 }<br> | 
        
    
 
    
        
            26 | 
            10 mod 3=${10 mod 3 }<br> | 
        
    
 
    
        
            39 | 
             value1:${empty value1 }<br> | 
        
    
 
    
        
            40 | 
             value2:${empty value2 }<br> | 
        
    
 
    
        
            41 | 
             value3:${empty value3 }<br> | 
        
    
 
    
        
            42 | 
             value4:${empty value4 }<br> | 
        
    
 
    
        
            43 | 
             value4:${!empty value4 }<br> | 
        
    
 
  
  一般要使用到的功能基本上如上。