关于Struts2中的标签介绍(二)

        6、<s:fielderror/>
        该标签主要用于在页面上输出在Action中设置的FieldError信息。用法如下所示:
// TestStruts2Tag.java
import  com.opensymphony.xwork2.ActionSupport;
public   class  TestStruts2Tag  extends  ActionSupport  {
    @Override
    
public String execute() throws Exception {
        
// TODO Auto-generated method stub
        return  SUCCESS;
    }


    @Override
    
public void validate() {
        
// TODO Auto-generated method stub
        this.addActionError("actionError!");
        
this.addActionMessage("actionMessage!");
        
this.addFieldError("field""fieldError");
        
this.addFieldError("field2""fieldError2");
    }

}
// index.jsp部分代码
< s:fielderror />
   
< s:fielderror >
           
< s:param > field </ s:param >
           
< s:param > field2 </ s:param >
   
</ s:fielderror >
// struts.xml
<! DOCTYPE struts PUBLIC
    
" -//Apache Software Foundation//DTD Struts Configuration 2.0//EN "
    
" http://struts.apache.org/dtds/struts-2.0.dtd " >

< struts >
    
< include file = " struts-default.xml " />
    
< package  name = " TestStruts2Tag "   extends = " struts-default " >
        
< action name = " testTag "   class = " TestStruts2Tag " >
            
< result name = " success " >/ index.jsp </ result >
            
< result name = " input " >/ index.jsp </ result >
        
</ action >
    
</ package >
</ struts >
        注:<s:fielderror />用于输出所有FieldError信息。
                <s:fielderror>
          <s:param>field</s:param>
          <s:param>field2</s:param>
      </s:fielderror>
                或
                <s:fielderror>
             <s:param value="%{'field'}" />
             <s:param value="%{'field2'}" />
       </s:fielderror>
                用于输出"field"和"field2"的信息。
            7、<s:actionerror/>
            用于输出ActionError信息。用法如下所示:
< s:actionerror />
            8、用于输出ActionMessage信息。用法如下所示:
< s:actionmessage />
             

你可能感兴趣的:(关于Struts2中的标签介绍(二))