Fork me on GitHub

OGNL入门

------------------siwuxie095

   

   

   

   

   

   

   

OGNL 入门

   

   

1、OGNL 支持对象方法调用,即 objName.methodName()

   

如:使用 OGNL 表达式 + Struts2 标签计算字符串长度

   

   

   

2、具体步骤

   

(1)在 JSP 页面引入 Struts2 标签库

   

   

   

   

(2)在 Struts2 标签中使用 OGNL 表达式实现操作

   

   

   

   

3、具体实现

   

1)编写页面

   

ognl.jsp:

   

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

   

<!-- 引入 Struts2 标签库 -->

<%@ taglib uri="/struts-tags" prefix="s"%>

   

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>OGNL</title>

</head>

<body>

   

<!--

s 前缀:即 Struts2 标签库的别名

 

property 标签:Struts2 的标签之一

 

value 属性值:写 OGNL 表达式

-->

 

<!-- 计算 helloworld 字符串的长度 -->

<s:property value="'helloworld'.length()"/>

   

</body>

</html>

   

   

   

2)访问路径

   

http://localhost:8080/工程名/ognl.jsp

   

   

   

   

   

   

   

   

   

【made by siwuxie095】

posted on 2017-08-10 21:35  siwuxie095  阅读(157)  评论(0编辑  收藏  举报

导航