日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Ognl标签常用例子 只能在Struts2中使用

發(fā)布時間:2025/3/20 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ognl标签常用例子 只能在Struts2中使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

效果如下圖:



ognl.jsp頁面

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>title</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><!-- Ognl標簽使用 --><%--映射棧:帶# --%><s:property value="#name"/><br/><s:property value="#request.name"/><br/><s:property value="#session.name"/><br/><s:property value="#application.name"/><br/><s:property value="#parameters"/><br/> <%--參數(shù) --%><s:property value="#attr.request.name"/><br/> <%--attribute將request、session和application封裝起來 --%><s:property value="#attr.session.name"/><br/><s:property value="#attr.application.name"/><br/><%--ognl算法 --%><s:property value="30+20"/><br/><s:property value="true&&true"/><br/><s:property value="true&&false"/><br/><s:property value="true||false"/><br/><s:property value="false||false"/><br/><s:property value="!false"/><br/><s:property value="false?'真的':'假的'"/><br/><%--創(chuàng)建數(shù)組或集合 --%><s:property value="{'小火','傻鳥','小黑','十品'}"/><br/><%--集合 --%><s:property value="#{'1':'小火','2':'傻鳥','3':'小黑','4':'十品'}"/><s:debug></s:debug></body> </html>


ognlDemo.java

package star.july.ognl; import java.util.Map; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class OgnlDemo extends ActionSupport{Student student;public void setStudent(Student student) {this.student = student;}public String set(){student.setName("陳二狗");ActionContext ac = ActionContext.getContext();//自己放值ac.put("name", student);Map rp = (Map) ac.get("request");rp.put("name", student);Map<String, Object> session = ac.getSession();session.put("name", student);Map<String, Object> application = ac.getApplication();application.put("name", student);Map<String, Object> parameters = ac.getParameters();parameters.put("name", student);System.out.println(student);return SUCCESS;} }實體類,Student.java package star.july.ognl; public class Student {public String name;public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic String toString() {return "Student [name=" + name + "]";}}


xml配置:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"> <struts><package name="student" namespace="/" extends="struts-default"><action name="student" class="star.july.ognl.OgnlDemo" method="set"><result name="success">/ognl.jsp</result></action></package></struts>

總結(jié)

以上是生活随笔為你收集整理的Ognl标签常用例子 只能在Struts2中使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。