OGNL

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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值