Struts 1 学习笔记-3-1(EL表达式的使用)
来源:互联网 发布:sleep函数 linux 编辑:程序博客网 时间:2024/06/10 12:43
发现EL使用起来挺方便,至少不用<%= %>了,如果单纯使用EL不需要引入jar包,本人是将其与Struts整合使用。
1.首先是我的Struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<action path="/jstlel" type="com.codedestiny.struts.JSTLELAction">
<forward name="success" path="/jstlel.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<action path="/jstlel" type="com.codedestiny.struts.JSTLELAction">
<forward name="success" path="/jstlel.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
2.JSTLELAction.java
package com.codedestiny.struts;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class JSTLELAction extends Action ...{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception ...{
request.setAttribute("hello", "Hello World");
Group relatedGroup = new Group();
relatedGroup.setName("SUN");
User u = new User();
u.setUsername("CodeDestiny");
u.setAge(21);
u.setRelatedGroup(relatedGroup);
request.setAttribute("user", u);
Map<String, Integer> hashMap = new HashMap<String, Integer>();
hashMap.put("key1", 1);
hashMap.put("key2", 2);
request.setAttribute("map", hashMap);
String[] array = new String[]...{"a", "b", "c", "d"};
request.setAttribute("array", array);
request.setAttribute("value1", "");
request.setAttribute("value2", new ArrayList());
request.setAttribute("value3", new int[]...{1, 2});
return mapping.findForward("success");
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class JSTLELAction extends Action ...{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception ...{
request.setAttribute("hello", "Hello World");
Group relatedGroup = new Group();
relatedGroup.setName("SUN");
User u = new User();
u.setUsername("CodeDestiny");
u.setAge(21);
u.setRelatedGroup(relatedGroup);
request.setAttribute("user", u);
Map<String, Integer> hashMap = new HashMap<String, Integer>();
hashMap.put("key1", 1);
hashMap.put("key2", 2);
request.setAttribute("map", hashMap);
String[] array = new String[]...{"a", "b", "c", "d"};
request.setAttribute("array", array);
request.setAttribute("value1", "");
request.setAttribute("value2", new ArrayList());
request.setAttribute("value3", new int[]...{1, 2});
return mapping.findForward("success");
}
}
3.与之对应的jstlel.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<h1>测试EL表达式</h1>
<hr>
<li>简单的EL表达式,其用法是 $ 和 ...{ }</li><br>
1 + 2 = $...{1 + 2} <br>
2 × 10 = $...{2 * 10} <br>
<hr>
<li>EL表达式隐式对象:pageScope,requestScope,sessionScope,applicationScope等,如果未指定scope,它的搜索顺序是:page~application</li><br>
hello(jsp):<%= request.getAttribute("hello") %><br>
hello(el): $...{hello}<br>
hello(el scope=requestScope): $...{requestScope.hello}
<hr>
<li>使用.进行导航,也称存储器</li><br>
姓名: $...{ user.username } <br>
年龄: $...{ user.age } <br>
所属组: $...{ user.relatedGroup.name } <br>
<hr>
<li>使用存储器取出map中的值</li><br>
map.key1 : $...{ map.key1 } <br>
map.key2 : $...{ map.key2 } <br>
<hr>
<li>用[]对数组中的元素进行访问</li><br>
array[1] : $...{ array[1] } <br>
<hr>
<li>EL支持的表达式</li><br>
10 / 5 = $...{ 10 / 5 } <br>
10 div 5 = $...{ 10 div 5 } <br>
10 % 5 = $...{ 10 % 5 } <br>
10 mod 5 = $...{ 10 mod 5 } <br>
<!--
== 在EL中可表示为 eq
!= 在EL中可表示为 ne
< 在EL中可表示为 lt
> 在EL中可表示为 gt
<= 在EL中可表示为 le
>= 在EL中可表示为 ge
&& 在EL中可表示为 and
|| 在EL中可表示为 or
! 在EL中可表示为 not
/ 在EL中可表示为 div
% 在EL中可表示为 mod
-->
<hr>
<li></li>测试empty<br>
value1 empty ? : $...{ empty value1 } <br>
value2 empty ? : $...{ empty value2 } <br>
value3 empty ? : $...{ empty value3 } <br>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<h1>测试EL表达式</h1>
<hr>
<li>简单的EL表达式,其用法是 $ 和 ...{ }</li><br>
1 + 2 = $...{1 + 2} <br>
2 × 10 = $...{2 * 10} <br>
<hr>
<li>EL表达式隐式对象:pageScope,requestScope,sessionScope,applicationScope等,如果未指定scope,它的搜索顺序是:page~application</li><br>
hello(jsp):<%= request.getAttribute("hello") %><br>
hello(el): $...{hello}<br>
hello(el scope=requestScope): $...{requestScope.hello}
<hr>
<li>使用.进行导航,也称存储器</li><br>
姓名: $...{ user.username } <br>
年龄: $...{ user.age } <br>
所属组: $...{ user.relatedGroup.name } <br>
<hr>
<li>使用存储器取出map中的值</li><br>
map.key1 : $...{ map.key1 } <br>
map.key2 : $...{ map.key2 } <br>
<hr>
<li>用[]对数组中的元素进行访问</li><br>
array[1] : $...{ array[1] } <br>
<hr>
<li>EL支持的表达式</li><br>
10 / 5 = $...{ 10 / 5 } <br>
10 div 5 = $...{ 10 div 5 } <br>
10 % 5 = $...{ 10 % 5 } <br>
10 mod 5 = $...{ 10 mod 5 } <br>
<!--
== 在EL中可表示为 eq
!= 在EL中可表示为 ne
< 在EL中可表示为 lt
> 在EL中可表示为 gt
<= 在EL中可表示为 le
>= 在EL中可表示为 ge
&& 在EL中可表示为 and
|| 在EL中可表示为 or
! 在EL中可表示为 not
/ 在EL中可表示为 div
% 在EL中可表示为 mod
-->
<hr>
<li></li>测试empty<br>
value1 empty ? : $...{ empty value1 } <br>
value2 empty ? : $...{ empty value2 } <br>
value3 empty ? : $...{ empty value3 } <br>
</body>
</html>
- Struts 1 学习笔记-3-1(EL表达式的使用)
- struts之el表达式简单学习笔记
- [学习笔记] EL 使用EL表达式获得作用域属性
- 学习笔记:EL 表达式
- EL表达式学习笔记
- EL表达式学习笔记
- EL表达式学习笔记
- EL表达式学习笔记
- Struts 1 学习笔记-2-1(Struts标签的使用步骤)
- EL表达式的学习
- JSTL EL表达式学习笔记
- EL表达式 学习笔记(JSTL)
- JSP学习笔记---el表达式
- EL表达式—学习笔记
- JavaWeb(EL表达式学习笔记)
- Java学习笔记:EL表达式
- EL表达式的使用
- El表达式的使用
- java编程思想学习笔记(javadoc)
- 学习编译原理
- 对一个博客的回复
- 关于纹理坐标
- CSDN上的Silverlight技术专题页
- Struts 1 学习笔记-3-1(EL表达式的使用)
- 出现错误“"0x7c938fea"指令引用的"0x00000010"内存。该内存不能为"written"。”的另一种可能性
- CS0016: 未能写入输出文
- css3.0抢先看(七):HSL和HSLA,RGBA全新的定义颜色方法
- 破解Email账号的三种方法
- 破解Email账号的三种方法
- 在 Ubuntu 下快速安装 IE 浏览器
- 雅虎为什么不愿卖给微软
- 08年的高中同学聚会