黑马程序员技术交流社区

标题: Struts标签set范围问题 [打印本页]

作者: 马亚冲    时间: 2011-9-11 09:52
标题: Struts标签set范围问题
struts2.1关于set标签范围测试的,怎么结果都一样啊????[code=jscript]<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<html>
  <head>   
    <title>tags.jsp</title>
  </head>
  
  <body>
    <h1>tags</h1>
        property 取得Action属性的值,值栈中存在:<s:property value="name"/>

        property 只是一个字符串:<s:property value="'zifuchuan'"/>

        <hr/>
<!--以下是出问题的代码: -->

        set:默认
<s:set var="admin" value="name"/>
        <strong>page(admin): </strong><s:property value="admin"/>

        <strong>request(#request.admin): </strong><s:property value="#request.admin"/>

        <strong>session(#session.admin): </strong><s:property value="#session.admin"/>

        <strong>application(#application.admin): </strong><s:property value="#application.admin"/>

        <strong>ActionContext(#admin): </strong><s:property value="#admin"/>
<hr/>




        set:(page)
<s:set var="admin" value="name" scope="page"/>
        <strong>page(admin): </strong><s:property value="admin"/>

        <strong>request(#request.admin): </strong><s:property value="#request.admin"/>

        <strong>session(#session.admin): </strong><s:property value="#session.admin"/>

        <strong>application(#application.admin): </strong><s:property value="#application.admin"/>

        <strong>ActionContext(#admin): </strong><s:property value="#admin"/>
<hr/>
        set:(request)
<s:set var="admin" value="name" scope="request"/>
        <strong>page(admin): </strong><s:property value="admin"/>

        <strong>request(#request.admin): </strong><s:property value="#request.admin"/>

        <strong>session(#session.admin): </strong><s:property value="#session.admin"/>

        <strong>application(#application.admin): </strong><s:property value="#application.admin"/>

        <strong>ActionContext(#admin): </strong><s:property value="#admin"/>
<hr/>
        set:(session)
<s:set var="admin" value="name" scope="session"/>
        <strong>page(admin): </strong><s:property value="admin"/>

        <strong>request(#request.admin): </strong><s:property value="#request.admin"/>

        <strong>session(#session.admin): </strong><s:property value="#session.admin"/>

        <strong>application(#application.admin): </strong><s:property value="#application.admin"/>

        <strong>ActionContext(#admin): </strong><s:property value="#admin"/>
<hr/>
       

        set:(application)
<s:set var="admin" value="name" scope="application"/>
        <strong>page(admin): </strong><s:property value="admin"/>

        <strong>request(#request.admin): </strong><s:property value="#request.admin"/>

        <strong>session(#session.admin): </strong><s:property value="#session.admin"/>

        <strong>application(#application.admin): </strong><s:property value="#application.admin"/>

        <strong>ActionContext(#admin): </strong><s:property value="#admin"/>
<hr/>
        <s:debug></s:debug>
  </body>
</html>[/code]以下是单独每个范围的测试结果:[code=jscript]每个范围分别测试的结果
set:默认
page(admin): MaYachong
request(#request.admin): MaYachong
session(#session.admin): MaYachong
application(#application.admin): MaYachong
ActionContext(#admin): MaYachong


set:(page)
page(admin): MaYachong
request(#request.admin): MaYachong
session(#session.admin):
application(#application.admin): MaYachong
ActionContext(#admin): MaYachong

set:(request)
page(admin): MaYachong
request(#request.admin): MaYachong
session(#admin): MaYachong
application(#application.admin): MaYachong
ActionContext(#admin): MaYachoeng

set:(session)
page(admin): MaYachong
request(#request.admin): MaYachong
session(#session.admin): MaYachong
application(#application.admin): MaYachong
ActionContext(#admin): MaYachong



set:(application)
page(#admin): MaYachong
request(#request.admin): MaYachong
session(#session.admin): MaYachong
application(#application.admin): MaYachong
ActionContext(#admin): MaYachong[/code]
作者: 匿名    时间: 2011-9-11 10:06
大哥,你学到这么后我感觉压力好大的
作者: 匿名    时间: 2011-9-12 10:40
标题: 回复 沙发 的帖子
基础没有你牢固,学完这个框架后,我还有回头使劲复习呢,前面的好多都忘了。复习java的时候,还请多多帮助啊
作者: 匿名    时间: 2011-9-13 08:24
谁能给个简单点又有深度的问题让我来回答一下。
作者: 匿名    时间: 2011-9-13 15:42
你试试[code]<s:set name="admin" value="name"/>[/code]把那个var改成name  set好像必须要name属性。[code][/code]
作者: 匿名    时间: 2011-9-13 23:55
楼上几位,我的问题解决了....、
看来还得自己仔细点啊...
问题的症结是我没有认识清内置对象属性。。。。
谢谢楼上几位了!!!!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2