struts2[3.3]OGNL表达式语句与struts2框架的结合原理

    1.1OGNL由三个部分组成:表达式、Root、Context。而Root和Context组成了OGNLContext,struts2的一个OGNLContext叫做ValueStack,而valueStack就是由Root和Context组成。在Root中存放的是栈;在Context中存放的是ActionContext 数据中心。

啥是栈呢?栈是一种数据结构,我们简单的了解一下,它的数据装载方式为先进后出,

具体需要深入了解的同学可以注意一下!

1.2栈原理

栈里面放的是什么呢?我们看一个例子:

新建一个Demo1Action.class:

package com.aisino.b_showVS;

import com.opensymphony.xwork2.ActionSupport;

public class Demo1Action extends ActionSupport {

	@Override
	public String execute() throws Exception {
		
		System.out.println("Demo1Action");
		return SUCCESS;
	}

	
}

再新建一个转发页面showVS.jsp:

扫描二维码关注公众号,回复: 4274583 查看本文章
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- 我们需要导一个debug标签,她是struts2内置标签 -->
<%@ taglib prefix="s" uri="/struts-tags" %>
<!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>Insert title here</title>
</head>
<body>
	<!-- 调试标签 -->
	<s:debug></s:debug>
</body>
</html>

在struts.xml中配置action:

<package name="showVS" namespace="/" extends="struts-default" >
		<action name="Demo1Action" class="com.aisino.b_showVS.Demo1Action" method="execute" >
			<result name="success" type="dispatcher" >/showVS.jsp</result>
		</action>
	</package>

在web.xml中配置核心过滤器:

 <!-- struts2核心过滤器 -->
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>

发布项目,访问http://localhost:8080/sturts2_day03Test/Demo1Action,点击一下[Debug]就可以看到我们的值栈存储的是什么东西了!

Root:

Context:

先到这里~

猜你喜欢

转载自blog.csdn.net/a_cherry_blossoms/article/details/84578358
今日推荐