首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

struts2标签详解(2)

2012-09-20 
struts2标签详解(二)java-web交流群:1326077631.action标签,可以在jsp中直接调用Action。package com.randy

struts2标签详解(二)
java-web交流群:132607763


1.action标签,可以在jsp中直接调用Action。

package com.randy.com;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class TagAction extends ActionSupport {private String author;public String execute() {return SUCCESS;}public String login() {ActionContext.getContext().put("author", getAuthor());return SUCCESS;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;}}

<action name="tag" name="code"><%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!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=ISO-8859-1"><title>Insert title here</title></head><body>hello,<s:property value="author"/></body></html>

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s" %><!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=ISO-8859-1"><title>Insert title here</title></head><body><s:action name="tag" executeResult="true" ignoreContextParams="false"></s:action></body></html>

用action标签可直接调用action。name属性指定action,namespace指定action的命名空间,executeResult指定是否将action处理结果页面包含到本页面中来,默认为true,ignoreContextParams指定页面的请求参数是否传入到action,默认为false,表示传入。
2.bean标签,用于创建一个javabean。
<s:bean name="com.randy.com.util.MyComparator" var="mycomparator"></s:bean><s:sort comparator="#mycomparator" source="{'a','aaaa','aa','bbd','n'}" var="sortList"></s:sort>

其中name属性指定javabean的实现类,包括包;var属性指定bean的名称。还可为bean指定用param标签使用参数。
3.date标签,用于对时间格式化输出。
<s:date name="#now" format="dd/MM/yyyy"/><s:date name="#now" format="yyyy/MM/dd"/><s:date name="#now" format="dd/MM/yyyy" nice="true"/>

format属性指定格式化的格式,name属性指定日期值,nice属性用于指定是否输出当前时刻和指定时刻的时差。
4.debug标签,用于辅助调试,加入这个标签后页面将会有个debug连接,点击可查看调试信息。
5.include标签,包含jsp页面或者servlet,还可指定param。
6.param标签,用于为提供其他标签提供参数。
7.set标签,设置值。name属性指定名,value指定值,scope指定范围。
8.url标签,用于产生一个url地址。
9.property标签,用于输出指定值。default属性,当value为null时,选用default指定值。
10.i18n国际化标签。
<s:i18n name="tmp"><s:text name="loginPage"></s:i18n>

热点排行