---
title: "表单提交到struts2 和表单提交到springmvc的controller"
author: "mywebcode"
date: "2014-04-10T23:14:00Z"
tags: []
slug: "struts2-springmvc-controller"
draft: false
lastmod: "2014-04-30T09:15:51Z"
id: 2058300
url: "https://mywebcode.iteye.com/blog/2058300"
---

我们直接上例子吧。

&lt;form id="sampleform" method="post" action="addstore.html"&gt;  
&lt;fieldset&gt;

&lt;p&gt;  
&lt;label class="required" for="name"&gt;名称：&lt;/label&gt;&lt;br /&gt; &lt;input  
type="text" id="name" class="half" name="storeInfo.name"  
onblur="checkName(id);" /&gt;  
&lt;/p&gt;

&lt;p&gt;  
&lt;label class="required" for="mallStatus"&gt;店铺类别：&lt;/label&gt;&lt;br /&gt; &lt;select  
id="mallStatus" class="input-text" style="width: 180px;"  
name="storeInfo.mallStatus"&gt;  
&lt;s:iterator value="mallstatus" var="temp"&gt;  
&lt;option value="${temp }"&gt;${temp.value }&lt;/option&gt;  
&lt;/s:iterator&gt;  
&lt;/select&gt;  
&lt;/p&gt;

&lt;p&gt;  
&lt;label class="required"&gt;所属频道：&lt;/label&gt;&lt;br /&gt; &lt;select  
class="input-text" name="storeInfo.channel" style="width: 180px;"&gt;  
&lt;option value="10"&gt;频道&lt;/option&gt;

&lt;/select&gt;  
&lt;/p&gt;

&lt;p&gt;  
&lt;label class="required" for="address"&gt;公司地址：&lt;/label&gt;&lt;br /&gt;  
&lt;table&gt;  
&lt;tr&gt;  
&lt;td&gt;&lt;select name="new\_province" id="new\_province"  
class="ordslt" onchange="changeprovice()"&gt;&lt;option  
value="0"&gt;请选择...&lt;/option&gt;  
&lt;s:iterator value="catalogAddressOneList" var="var"&gt;  
&lt;option value="${var.id }"&gt;${var.name }&lt;/option&gt;  
&lt;/s:iterator&gt;  
&lt;/select&gt;  
&lt;/tr&gt;

&lt;/table&gt;  
&lt;/p&gt;

&lt;p&gt;  
&lt;label class="required"&gt;是否vip：&lt;/label&gt;&lt;br /&gt; &lt;input type="radio"  
id="isVip1" class="" value="false" name="storeInfo.vip"  
checked="checked" /&gt; &lt;label class="choice" for="dateformat1"&gt;否&lt;/label&gt;  
&lt;input type="radio" id="isVip2" class="" value="true"  
name="storeInfo.vip" /&gt; &lt;label class="choice" for="dateformat2"&gt;是&lt;/label&gt;  
&lt;/p&gt;

&lt;p class="box"&gt;  
&lt;input type="submit" class="btn btn-green big" value="确定" /&gt; &lt;input  
type="reset" class="btn btn-green big" value="重置" /&gt; &lt;input  
type="button" class="btn btn-green big" onclick="goBack();"  
value="返回" /&gt;  
&lt;/p&gt;

&lt;/fieldset&gt;

&lt;/form&gt;

我们看标红的。。数据库中应有StoreInfoEntity 并且该实体应该有标红的字段。

Action中只用 使用 private StoreInfoEntity storeInfo; 实现其get和set方法。

这里尤其看一下 select 和radio 中name的写法

在springmvc中 所有的字段名字跟实体属性的名字一样就可以，不需要使用store.name,直接使用name 即可。

接收使用 @ModelAttribute(value="storeInfo") StoreInfoEntity storeInfo