1. 程式人生 > >javaweb的表單提交程式碼參考示例

javaweb的表單提交程式碼參考示例



<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/page.tld" prefix="page"%>
<script type="text/javascript" src="includes/selection.js"></script>
<script type="text/javascript" src="includes/jquery-1.3.2.js"></script>
<script type="text/javascript">
function save()
    {
    var code = document.getElementById("code").value;  //庫房名稱
    var name = document.getElementById("name").value;  //庫房編碼
    
         
    var a=true;
               
            //庫區最大儲存量數字驗證
            if (isNaN(document.getElementById("largest_inventory").value)) {
      alert("最大儲存量必須是數字");
      document.getElementById("largest_inventory").focus();
     
      return false;
      }
        if((insertStoreRoom.code.value!=""))
        {
            if((insertStoreRoom.name.value!=""))
            {
             if(insertStoreRoom.address.value!=""){
              if(insertStoreRoom.largest_inventory.value!=""){
               
               $.ajax({//驗證庫房編碼或庫房名稱重複
       

url:"checkStoreRoomCodeAndName.do",
       cache : false,
       type : "post",
       data : {"code":code,"name":name},
       async:false,
       dataType : "json",
       success:function(result){
         
         if(result==1){
          alert("庫房編碼或庫房名稱重複");
          a=false;
         }
        }
       });
               
               if(a){
        var form = document.insertStoreRoom; //獲取此元素
                  form.action="insertStoreRoom.do";
                  form.submit();
                  }else{
                   alert("重新填寫資料");
                   return false;
                  }
              }else{
               alert("最大資料量不能為空");
              }
               }else{
                alert("地址不能為空");
               }
            }
            else
            {
                alert("庫房名稱不能為空");
                }
            }
        else
        {
            alert("庫房編碼不能為空");
            }
        }


</script>
<html:javascript formName="storeRoomForm" staticJavascript="false" />
<html:form action="/insertStoreRoom" styleId="insertStoreRoom">
 <table width=90% border=0 cellpadding=4 cellspacing=0>
  <tr>
  <td class="bluetext">
    <bean:message key="travelApplication.site" />:
    &nbsp;
   </td>
    <td>
    <html:select property="site_id">
    <html:options collection="x_siteList" property="id" labelProperty="name"/>
    </html:select>
    </td>
  </tr>
  <tr>
   <td class="bluetext">庫房編碼:</td>
   <td><html:text property="code" /><span class="required">*</span></td>
  </tr>
  <tr>
   <td class="bluetext">庫房名稱:</td>
   <td><html:text property="name" /><span class="required">*</span></td>
  </tr>
  <tr>
   <td class="bluetext">地址:</td>
   <td><html:text property="address" styleId="address" /><span class="required">*</span></td>
  </tr>
  <tr>
   <td width="15%" class="bluetext">時間:</td>
   <td>
    <html:text property="date" readonly="true" size="15" />
    <a onclick="event.cancelBubble=true;" href="javascript:showCalendar('dimg2',false,'date',null,null,'storeRoomForm')">
    <img align="absmiddle" border="0" id="dimg2" src="images/datebtn.gif" /> </a>
   </td>
  </tr>
  <tr>
   <td class="bluetext">型別:</td>
   <td><html:select property="type" >
   
      <c:if test="${sessionScope.LOGIN_USER.locale=='en'}"><html:options collection = "x_STOREROOMTYPELIST" property = "enumCode" labelProperty = "engShortDescription"/>
     
     
      </c:if>
              <c:if test="${sessionScope.LOGIN_USER.locale!='en'}"><html:options collection = "x_STOREROOMTYPELIST" property = "enumCode" labelProperty = "chnShortDescription"/>
               
              </c:if>
   </html:select>
   <span class="required">*</span></td>
  </tr>
  
  <%--<tr>
   <td class="bluetext">安全庫存:</td>
   <td><html:text property="largest_inventory" /><span class="required">*</span></td>
  </tr>
  --%>
  <tr>
   <td class="bluetext">最大儲存量</td>
   <td><html:text property="largest_inventory"/><span class="required">*</span></td>
  </tr>
  <tr>
   <td class="bluetext">狀態:</td>
   <td><html:select property="status">
    <c:if test="${sessionScope.LOGIN_USER.locale=='zh'}">
     <html:options collection="X_ENABLEDDISABLEDLIST"
      property="enumCode" labelProperty="chnShortDescription" />
    </c:if>
    <c:if test="${sessionScope.LOGIN_USER.locale!='zh'}">
     <html:options collection="X_ENABLEDDISABLEDLIST"
      property="enumCode" labelProperty="engShortDescription" />
    </c:if>
   </html:select></td>
  </tr>
  <tr>
   <td class="bluetext">備註:</td>
   <td><html:textarea property="remark" cols="20" rows="3" /></td>
  </tr>
 </table>
 <hr />
 <div align="center">
   <%--<html:submit><bean:message key="all.save" /></html:submit>
   --%><input type="button" value="儲存" onclick="save()"/>
   &nbsp;&nbsp;&nbsp;&nbsp;
   <input type="button" value="關閉" onclick="window.close();"/>
 </div>
</html:form>