如果类型是object Structs会把它默认解析为OGNL表达式

想取字符串的话就 ‘’ ‘ ’ ‘’

jar包

web.xml、

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <filter>
<filter-name>struts2</filter-name>
<!--<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>-->
<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>
</web-app>

Structs.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!--<constant name="struts.enable.DynamicMethodInvocation" value="false" />-->
<constant name="struts.devMode" value="true" />
<!--<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>-->
<constant name="struts.ui.theme" value="simple" />
<package name="tags" extends="struts-default"> <action name="tags" class="com.bjsxt.struts2.tags.TagsAction">
<result>/tags.jsp</result>
</action> </package> </struts>

Dog.java

package com.bjsxt.struts2.tags;

public class Dog {

    private String name;

    public Dog() {

    }

    public Dog(String name) {
super();
this.name = name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} @Override
public String toString() {
return "dog: " + name;
}
}

S.hava

package com.bjsxt.struts2.tags;

public class S {
public static String STR = "STATIC STRING"; public static String s() {
return "static method";
}
}

TagsAction.java

package com.bjsxt.struts2.tags;

import com.opensymphony.xwork2.ActionSupport;

public class TagsAction extends ActionSupport {

    private String password;

    private String username;

    public TagsAction() {
} public String execute() {
this.addFieldError("fielderror.test", "wrong!");
return SUCCESS;
} public String getPassword() {
return password;
} public String getUsername() {
return username;
} public void setPassword(String password) {
this.password = password;
} public void setUsername(String username) {
this.username = username;
} }

User.java

package com.bjsxt.struts2.tags;

public class User {
private int age = ; public User() { } public User(int age) {
super();
this.age = age;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} @Override
public String toString() {
return "user" + age;
}
}

index.jsp

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%> <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Insert title here</title>
</head>
<body>
访问属性
<a href="http://localhost:6666//Struts2_2000_StrutsTags/tags.action?username=u&password=p">tags</a>
</body>
</html>

具体用法建议使用的时候再回来参考

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>Struts-Tags学习</title>
</head>
<body>
<ol>
<li>property: <s:property value="username"/> </li>
<li>property 取值为字符串: <s:property value="'username'"/> </li>
<li>property 设定默认值: <s:property value="admin" default="管理员"/> </li>
<li>property 设定HTML: <s:property value="'<hr/>'" escape="false"/> </li>
<hr />
<li>set 设定adminName值(默认为request 和 ActionContext): <s:set var="adminName" value="username" /></li> <li>set 从request取值: <s:property value="#request.adminName" /></li>
<li>set 从ActionContext取值: <s:property value="#adminName" /></li> <%--<li>set 设定范围: <s:set name="adminPassword" value="password" scope="page"/></li>
<li>set 从相应范围取值: <%=pageContext.getAttribute("adminPassword") %></li>
--%>
<li>set 设定var,范围为ActionContext: <s:set var="adminPassword" value="password" scope="session"/></li>
<li>set 使用#取值: <s:property value="#adminPassword"/> </li>
<li>set 从相应范围取值: <s:property value="#session.adminPassword"/> </li> <hr /> <%--<li>push:<s:set name="myDog" value="new com.bjsxt.struts2.ognl.Dog('oudy')"></s:set></li>
<li>
push:<s:push value="#myDog">
<s:property value="name"/>
</s:push>
</li>
<li>push: <s:property value="name"/></li>
--%> <hr />
<li>bean 定义bean,并使用param来设定新的属性值:
<s:bean name="com.bjsxt.struts2.tags.Dog" >
<s:param name="name" value="'pp'"></s:param>
<s:property value="name"/> </s:bean> </li> <li>bean 查看debug情况:
<s:bean name="com.bjsxt.struts2.tags.Dog" var="myDog">
<s:param name="name" value="'oudy'"></s:param>
</s:bean>
拿出值:
<s:property value="#myDog.name"/> </li>
<hr /> <li>include _include1.html 包含静态英文文件
<s:include value="/_include1.html"></s:include>
</li> <li>include _include2.html 包含静态中文文件
<s:include value="/_include2.html"></s:include>
</li> <li>include _include1.html 包含静态英文文件,说明%用法
<s:set var="incPage" value="%{'/_include1.html'}" />
<s:include value="%{#incPage}"></s:include>
</li> <hr /> <li>if elseif else:
age = <s:property value="#parameters.age[0]" /> <br />
<s:set var="age" value="#parameters.age[0]" />
<s:if test="#age < 0">wrong age!</s:if>
<s:elseif test="#parameters.age[0] < 20">too young!</s:elseif>
<s:else>yeah!</s:else><br /> <s:if test="#parameters.aaa == null">null</s:if>
</li> <hr /> <li>遍历集合:<br />
<s:iterator value="{1, 2, 3}" >
<s:property/> |
</s:iterator>
</li>
<li>自定义变量:<br />
<s:iterator value="{'aaa', 'bbb', 'ccc'}" var="x">
<s:property value="#x.toUpperCase()"/> |
</s:iterator>
</li>
<li>使用status:<br />
<s:iterator value="{'aaa', 'bbb', 'ccc'}" status="status">
<s:property/> |
遍历过的元素总数:<s:property value="#status.count"/> |
遍历过的元素索引:<s:property value="#status.index"/> |
当前是偶数?:<s:property value="#status.even"/> |
当前是奇数?:<s:property value="#status.odd"/> |
是第一个元素吗?:<s:property value="#status.first"/> |
是最后一个元素吗?:<s:property value="#status.last"/>
<br />
</s:iterator> </li> <li>
<s:iterator value="#{1:'a', 2:'b', 3:'c'}" >
<s:property value="key"/> | <s:property value="value"/> <br />
</s:iterator>
</li> <li>
<s:iterator value="#{1:'a', 2:'b', 3:'c'}" var="x">
<s:property value="#x.key"/> | <s:property value="#x.value"/> <br />
</s:iterator>
</li> <li> <s:fielderror fieldName="fielderror.test" theme="simple"></s:fielderror> </li>
</ol> </body>
</html>

include.jsp

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>_include</title>
</head>
<body>
params :<br />
使用property取参数:p1=<s:property value="#parameters.p1"/> <br />
使用property取参数:p2=<s:property value="#parameters.p2"/> <br />
使用property取参数:p3=<s:property value="#parameters.p3"/> <br />
</body>
</html>

_include1.html

Structs复习 Structs标签的更多相关文章

  1. Structs复习 开始 第一个helloworld项目

    大体已经学完ssh了  感觉一起做一个项目有点难 计划先用一下独立的Structs 然后再把数据库操作换成hibernate  然后在用Spring 整合 计划用10天左右吧 但今天开始用Struct ...

  2. Structs复习 OGNL

    Dominmodel只有传 User.age 类似的这种Structs才能帮创建对象 Dominmodel User里必须有空的构造方法 OGNL:OBJECT GRAPHIC NAVAGATION ...

  3. Structs复习 Result第二部分

    1.动态结果 2.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...

  4. Structs复习 Result第一部分

    Jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&q ...

  5. Structs复习 访问web元素

    Structs帮我们在action和http里建立了联系 主要有四种方式 我们主要用第二种(IOC 依赖容器注入 ) Jar包 web.XML <?xml version="1.0&q ...

  6. Structs复习 Action传递参数

    Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...

  7. Structs复习 通配符

    1.jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  8. Structs复习 Path问题

    Path问题相对复杂 主要是路劲问题 但结论很简单 就是统一使用绝对路径 jar包 web.xml <?xml version="1.0" encoding="UT ...

  9. Structs复习 Action

    引入jar包 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

随机推荐

  1. CentOS用户和用户组管理

    groupadd grptest1  按照系统默认的gid创建组.根uid一样,gid也是从1000开始的. groupadd -g 1008 grptest2    创建gid=1008的用户组:g ...

  2. Solr之精确、匹配、排序、模糊查询-yellowcong

    Solr查询数据,其实下面一堆的参数,我也没有做测试,只是转载过来了,我大概只用了高亮.排序.查询.分页,其他的好像没有用过,以后用再来查 一.基本查询 参数 意义 q 查询的关键字,此参数最为重要, ...

  3. angularjs指令中的scope

    共享 scope 使用共享 scope 的时候,可以直接从父 scope 中共享属性.因此下面示例可以将那么属性的值输出出来.使用的是父 scope 中定义的值. js代码: app.controll ...

  4. WPF圆角按钮与触发颜色变化

    <Button x:Name="button1" Content="按钮1" Margin="10,10,0,0" Cursor=&q ...

  5. unicode转中文以及str形态的unicode转中文

    今天在工作中遇到这样一个问题(工作环境为Python2.7.1),需要将一个字典中字符串形态的Unicode类型的汉字转换成中文,随便总结一下: 1.unicode转中文 old = u'\u4e2d ...

  6. ORA-00257: archiver error. Connect internal only, until freed【日志归档清理】

    select * from V$FLASH_RECOVERY_AREA_USAGE;  查看使用情况 用plsql登陆时提示“ORA-00257: archiver error. Connect in ...

  7. Ubuntu 14.04 配置OpenCv 2.4.9

      安装工具 g++ 链接:http://www.cnblogs.com/LQLin168/p/6844593.html 下载OpenCv 2.4.9(官网地址):http://opencv.org/ ...

  8. Excel2010隔行变色的实现方法 [也可套用格式即可]

    这样excel隔行变色的效果,excel会自动隔行填充不同颜色. 公式说明: =MOD(ROW(),2)=0,实现的效果是偶数行自动填充底纹颜色 =MOD(ROW(),2)=1,实现的效果是奇数行自动 ...

  9. 《算法》第四章部分程序 part 2

    ▶ 书中第四章部分程序,加上自己补充的代码,随机生成各类无向图 ● 随机生成无向图 package package01; import edu.princeton.cs.algs4.StdOut; i ...

  10. C# 设计模式-策略者模式(Strategy)

    策略模式的用意是针对一组算法,将每一个算法封装到具有共同接口的独立的类中,从而使得它们可以相互替换.策略模式使得算法可以在不影响到客户端的情况下发生变化. 策略模式是对算法的包装,是把使用算法的责任和 ...