Struts2标签(一)

Action:

package com.struts2.tag.exer.web.actions;

import com.opensymphony.xwork2.ActionSupport;

public class TagAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 1096330019952553956L;


public String append(){

return SUCCESS;
}

public String generator(){

return SUCCESS;
}

public String merge(){

return SUCCESS;
}


}



struts.xml:



"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">








/pages/{1}.jsp









index.jsp:

<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>


Tag Navigation Page
















  • append.jsp:

    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>



    append

























    style="background-color:#bbbbbb">







    Book Name Author









    style="background-color:#cccccc">





    Book Name Author






    generator.jsp:

    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ page import="java.util.*,com.opensymphony.xwork2.util.*" %>


    generator











    style="background-color:#bbbbbb">





    Book Name Author



    <%-- count属性限定了元素的数量 id属性将生成的集合放入了valueStack中--%>









    <%--

    ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");

    java.util.Iterator iterator= (java.util.Iterator)vs.findValue("books");
    if(iterator!=null){
    while(iterator.hasNext()){
    String book = (String)iterator.next();

    --%>

    <%--=book--%>

    <%--
    }
    }
    --%>







    Book Name Author







    merge.jsp

    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>


    merge


























    style="background-color:#bbbbbb">







    Merge
    Book Name Author















    style="background-color:#bbbbbb">







    Append
    Book Name Author




    你可能感兴趣的:(struts2)