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>
<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><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"/>
<s:i18n name="tmp"><s:text name="loginPage"></s:i18n>