OGNL

来源:互联网 发布:风暴大陆坐骑进阶数据 编辑:程序博客网 时间:2024/06/14 19:41

OGNL       对象导航图语言    作用:从值栈读取数据

值栈就是Struts 框架提供的一块内存

1:Action 会自动的被放入栈顶

成员变量    会自动放入root区

2   方法中有一个对象  运输到 界面显示

放入  valueStac;

push(info);


getRoot().push();

界面获取uname取值





package happy.day08valueStack.entity;/** * Created by Happy on 2017-10-24. */public class UserInfo {    private String username;    private String password;    public String getUsername() {        return username;    }    public void setUsername(String username) {        this.username = username;    }    public String getPassword() {        return password;    }    public void setPassword(String password) {        this.password = password;    }}

package happy.day08valueStack.action;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.util.ValueStack;import happy.day08valueStack.entity.UserInfo;/** * Created by Administrator on 2017/10/27 0027. */public class valueStack implements Action {    public String execute() throws Exception {        UserInfo info=new UserInfo();        info.setUsername("星星");        ValueStack vs= ActionContext.getContext().getValueStack();        vs.getRoot().push(info);        vs.push(info);        return SUCCESS;    }}
<?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>  <!--  不用重启服务-->    <constant name="struts.devMode" value="true"></constant><package name="happy.manymethod" namespace="/" extends="struts-default">    <action name="firstList" class="happy.manymethod.FirstAction" method="list">        <result name="list">day03/list.jsp</result>    </action> <!--   del-->    <action name="firstDel" class="happy.manymethod.FirstAction" method="del">        <result name="del">day03/del.jsp</result>    </action></package></struts>
 




Sttruts.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>    <constant name="struts.devMode" value="true"></constant>    <!--创建一个default包,继承自Struts2的struts-default包-->    <package name="default" namespace="/" extends="struts-default">        <interceptors>            <interceptor name="myInter" class="happy.day07interceptor.interceptor.MyInterceptor"></interceptor>            <interceptor-stack name="myStack">                <interceptor-ref name="defaultStack"></interceptor-ref>                <interceptor-ref name="myInter"></interceptor-ref>            </interceptor-stack>        </interceptors>        <default-interceptor-ref name="myStack"></default-interceptor-ref>        <default-action-ref name="first"></default-action-ref>        <global-results>            <result name="login">/WEB-INF/myinter/login.jsp</result>        </global-results>        <action name="first">        </action>        <!-- &lt;!&ndash;接受处理用户的/helloword.action请求,并根据返回结果,完成跳转&ndash;&gt;            <action name="helloword"                    class="cn.struts.one.HelloWordAction">                &lt;!&ndash;结果为”helloword时,跳转至helloword.jsp页面&ndash;&gt;                <result name="ss">helloword.jsp</result>            </action>-->    </package>    <!--<include file="stuts-03.xml"></include>    <include file="struts-day04.xml"></include>    <include file="struts-day05.xml"></include>    <include file="struts-day06.xml"></include> <include file="struts-day07.xml"></include>    -->    <include file="struts-day08.xml"></include></struts>
页面



<%@ taglib prefix="s" uri="/struts-tags" %><%--  Created by IntelliJ IDEA.  User: Administrator  Date: 2017/10/27 0027  Time: 上午 10:02  To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head>    <title>Title</title></head><body><s:property value="username"></s:property><s:debug/></body></html>


原创粉丝点击