美文网首页
struts标签

struts标签

作者: _FireFly_ | 来源:发表于2020-12-15 16:33 被阅读0次

    页面发起请求

    <%@ page pageEncoding="utf-8" %>
    <!doctype html>
    <html>
        <head> </head>
        <body>
            <a href="test1.do">test1</a>
        </body>
    </html>
    
    public class TestAction1 {
    
        private int age ;
        private String[] names ;
        public int getAge() {
            return age;
        }
        public String[] getNames() {
            return names;
        }
    
        public String t1(){
            System.out.println("----------t1----------");
    
            int age = 18 ;
            String[]  names = new String[]{"dmc1","dmc2","dmc3"} ;
    
            this.age= age ;
            this.names = names ;
    
            //request.setAttribute("names",names);
    
            //ActionContext.getContext().getValueStack().push(user{age=20});
            ActionContext.getContext().getSession().put("age",20);
            return "success" ;
        }
    
    }
    
    <%@ page pageEncoding="utf-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!doctype html>
    <html>
        <head>
    
        </head>
        <body>
            <s:property value="age" /> <br/>
            <s:property value="#session.age" />
            <hr/>
            <s:if test="age>=20" >
                已成年
            </s:if>
            <s:elseif test="age>=10">
                青少年
            </s:elseif>
            <s:else>
                幼年
            </s:else>
            <hr/>
            <s:iterator value="names" >
                <s:property />
            </s:iterator>
        </body>
    </html>
    

    struts.xml

    <?xml version="1.0"?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
            "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
        <constant name="struts.i18n.encoding" value="utf-8"></constant>
        <constant name="struts.action.extension" value="action,,do" />
        <constant name="struts.configuration.xml.reload" value="true" />
    
        <constant name="struts.custom.i18n.resources" value="dmc" ></constant>
    
       <package name="dmc" extends="struts-default" namespace="/">
            <action name="test1" class="com.action.TestAction1" method="t1">
                <result name="success" type="dispatcher">02.jsp</result>
            </action>
       </package>
    </struts>
    

    struts常用的标签

    <%@ page pageEncoding="utf-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <!doctype html>
    <html>
        <head>
    
        </head>
        <body>
            <s:form action="test2.do" method="post" >
                <s:textfield label="文本框" name="a" ></s:textfield>
                <s:password label="密码框" name="b"></s:password>
                <s:radio list="#{'1':'男','2':'女'}" label="单选按钮" name="c" value="1"></s:radio>
                <s:checkboxlist list="#{'1':'足球','2':'篮球','3':'排球'}" label="复选按钮" name="d"></s:checkboxlist>
                <s:select list="#{'1':'黑龙江','2':'吉林','3':'辽宁'}" label="下拉框" name="e"  ></s:select>
                <s:file label="文件选择框" name="f" ></s:file>
                <s:textarea label="文本域" name="g"></s:textarea>
                <s:reset value="重置"></s:reset>
                <s:submit></s:submit>
                <s:token></s:token>
            </s:form>
        </body>
    </html>
    
    image.png

    相关文章

      网友评论

          本文标题:struts标签

          本文链接:https://www.haomeiwen.com/subject/oauwgktx.html