首页 > 代码库 > struts2中<s:form>的应用

struts2中<s:form>的应用

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/admin/include/taglibs.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>TShop商城系统演示站 - Powered by TShop</title>
<%@include file="/admin/include/script.jsp"%>
</head>
<body>
<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3>店铺</h3>
      <ul class="tab-base">
        <li><a href="JavaScript:void(0);" class="current"><span>基本设置</span></a></li>

      </ul>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <s:form action="addStoreSetting.action" method="post" id="form_email" name="settingForm" > 
    <input type="hidden" name="form_submit" value="http://www.mamicode.com/ok" />
    <table class="table tb-type2">
      <tbody>
        <tr class="noborder">
          <td colspan="2" class="required"><label>开店申请:</label></td>
        </tr>
        <tr class="noborder">
        <input type="hidden" name=‘setting.id‘ value="http://www.mamicode.com/" />
<input type="hidden" name=‘setting.name‘ value="http://www.mamicode.com/store_allow_isuse" />
          <td class="vatop rowform onoff">
          <s:if test=‘setting.value == "1"‘>
            <label for="store_allow_isuse_1" class="cb-enable selected" title="开启"><span>开启</span></label>
            <label for="store_allow_isuse_0"class="cb-disable " title="关闭"><span>关闭</span></label>
          </s:if>
          <s:if test=‘setting.value == "0"‘>
          <label for="store_allow_isuse_1" class="cb-enable " title="开启"><span>开启</span></label>
            <label for="store_allow_isuse_0"class="cb-disable selected" title="关闭"><span>关闭</span></label>
          </s:if>
            <input type="radio" id="store_allow_isuse_1" name="setting.value" value="http://www.mamicode.com/1" <s:if test=‘setting.value == "1"‘>checked="checked"</s:if>>
            <input type="radio" id="store_allow_isuse_0" name="setting.value" value="http://www.mamicode.com/0" <s:if test=‘setting.value == "0"‘>checked="checked"</s:if>>
            </td>
          <td class="vatop tips"></td>
        </tr>
        <tr>
          <td colspan="2"><table class="table tb-type2 nomargin">
              <thead>
                <tr class="space">
                  <th colspan="16">信誉额度</th>
                </tr>
                <tr class="thead">
                  <th>等级</th>
                  <th>信用介于</th>
                </tr>
              </thead>
              <tbody>
              <s:if test="ruleList.size()>0">
              <s:iterator value="http://www.mamicode.com/ruleList" status="status">                  
             <s:hidden   label="id" name="ruleList[%{#status.index}].id" value="http://www.mamicode.com/%{ruleList[#status.index].id}"/> 
             <s:hidden  label="type" name="ruleList[%{#status.index}].type" value="http://www.mamicode.com/%{ruleList[#status.index].type}"/> 
             <s:hidden  label="name" name="ruleList[%{#status.index}].name"  value="http://www.mamicode.com/%{ruleList[#status.index].name}"/>
             <s:hidden  label="grade" name="ruleList[%{#status.index}].grade" value="http://www.mamicode.com/%{ruleList[#status.index].grade}"/>
               <tr class="hover">
                 <td class="w200"><span class="<s:property value=http://www.mamicode.com/‘name‘/> "><img src="http://121.52.216.217:10080/shopnc/admin/templates/images/transparent.gif"/></span></td>
                 <td>
                 <SPAN>
                 <s:textfield  name="ruleList[%{#status.index}].startValue"   value="http://www.mamicode.com/%{ruleList[#status.index].startValue}"/>-&nbsp;&nbsp;<s:textfield  name="ruleList[%{#status.index}].endValue"  value="http://www.mamicode.com/%{ruleList[#status.index].endValue}"/>
                 </SPAN>
                 </td>
                </tr>
                </s:iterator>
                </s:if>
              </tbody>
            </table></td>
        </tr>
      </tbody>
      <tfoot>
        <tr class="tfoot">
          <td colspan="2">
          <s:submit value="http://www.mamicode.com/提交"  /> 
          </td>
        </tr>
      </tfoot>
    </table>
  </s:form>
</div>
</body>
</html>
 
注意:1、<s:form>表单中action属性action="addStoreSetting.action"不用写成action="/admin/store/setting/addStoreSetting.action",struts2会自动匹配命名空间下的addStoreSetting.action,还有就是非<s:form>表单的文本域写法也能通过<s:from>提交到后台
2、由于使用struts2标签,页面样式受影响,所以需在struts2标签中加上theme="simple"才能够使原来的jsp页面样式不受影响。

struts2中<s:form>的应用