struts 2: Form 폼 에 여러 개의 submit 제출 문제 가 있 습 니 다.

페이지 에서 Buser 대상 으로 전 달 됩 니 다. BuserBean 의 속성 은:     private String URealname;     private String USex;     private String UTel;     private String UQq; get, set 방법 을 추가 합 니 다.1.register.jsp   
<s:form action="userAction">  
<table> 
  <tr> 
    <td>      </td> 
  </tr> 
  <tr> 
    <td>    </td> 
    <td><input name="buser.URealname" type="text" /></td> 
  </tr> 
  <tr> 
    <td>  </td> 
    <td><input type="radio" name="buser.USex" value=" "checked="checked"/>  
    <input type="radio" name="buser.USex" value=" " class="radio" /> 
       </td> 
  </tr> 
  <tr> 
    <td>    </td> 
    <td><input name="buser.UTel" type="text"/></td> 
  </tr> 
  <tr> 
    <td>QQ </td> 
    <td><input name="buser.UQq" type="text"/></td> 
  </tr> 
</table> 
  <s:submit value="  " method="ensure" /> 
  <s:submit value="  " method="view" /> 
  </s:form> 


 2.struts.xml
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration  
2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<!--   struts2          --> 
  <include file="struts-default.xml" /> 
  <!-- extends     struts2     package --> 
    <package name="struts2" extends="struts-default"> 
      <!-- action action      --> 
      <action name="userAction"  class="com.dgy.action.UserAction"> 
        <result name="ensure" >test.jsp</result> 
        <result name="view" >view.jsp</result> 
        <result name="input">register.jsp</result> 
      </action> 
    </package> 
</struts> 


 3.com.dgy.action.UserAction
package com.dgy.action; 
import com.dgy.javabean.BuserBean; 
import com.opensymphony.xwork2.ActionSupport; 

public class UserAction extends ActionSupport{ 
    BuserBean buser ; 
    public String ensure(){ 
        System.out.println("running ensure()!"); 
        return "ensure"; 
    } 
    public String view(){ 
        System.out.println("running view()!"); 
        this.setBuser(this.getBuser()); 
        return "view"; 
    } 
    public BuserBean getBuser() { 
        return buser; 
    } 
    public void setBuser(BuserBean buser) { 
        this.buser = buser; 
    } 
} 


 
4.view.jsp 
 
<s:iterator value="buser"> 
<table> 
  <tr> 
    <td>      </td> 
  </tr> 
  <tr> 
    <td>    </td> 
    <td ><s:property value="URealname"></s:property></td> 
  </tr> 
  <tr> 
    <td>  </td> 
    <td ><s:property value="USex"></s:property></td> 
  </tr> 
  <tr> 
    <td>    </td> 
    <td ><s:property value="UTel"></s:property></td> 
  </tr> 
  <tr> 
    <td>QQ </td> 
    <td><s:property value="UQq"></s:property></td> 
  </tr> 
</table> 
</s:iterator> 
<s:submit value="  " method="ensure" /> 
</s:form> 




좋은 웹페이지 즐겨찾기