我有一個JSP說myPage.jsp在JSP錯誤而提交第二形式存在於同一個JSP ....需要建議
我就吃2個格
如下每個格中包含一種形式:
DIV答:
<div class="validation-box">
<form:form id="compnay-detail" method="post" action="companySave.do" commandName="company">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="col"><label>Address Type</label> <form:input type="text" path="addressType" class="textbox" name="addressType" id="addType" maxlength="20" />
</td>
<td class="col"><label>Street</label> <form:input path="street"
class="textbox" name="street" id="street" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="3" class="no-padding">
<div class="button-pannel margin-top">
<span class="lhscrv"> <span class="rhscrv"> <input type="submit" class="bttn" id="saveAddress" value="Save" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="reset" value="Reset" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="cancel" value="Cancel" />
</span>
</span>
</td>
</tr>
</table>
</form:form>
</div>
DIV B:
<div class="validation-box">
<form:form id="compnayAddDetail" method="post" action="test.do" commandName="address">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="col"><label>Address Type</label> <form:input type="text" path="addressType" class="textbox" name="addressType" id="addType" maxlength="20" />
</td>
<td class="col"><label>Street</label> <form:input path="street"
class="textbox" name="street" id="street" maxlength="50" />
</td>
</tr>
<tr>
<td colspan="3" class="no-padding">
<div class="button-pannel margin-top">
<span class="lhscrv"> <span class="rhscrv"> <input type="submit" class="bttn" id="saveAddress" value="Save" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="reset" value="Reset" />
</span>
</span> <span class="lhscrv"> <span class="rhscrv"> <input
type="button" class="bttn" id="cancel" value="Cancel" />
</span>
</span>
</td>
</tr>
</table>
</form:form>
</div>
MY控制器類:
@RequestMapping("/companySave.do")
public String saveCompany(Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{
//...... code.......
return "redirect:/companyAddressPage/"+company.getId()+".do";
}
@RequestMapping("/companyAddressPage/{id}.do")
public String companyAddressPage(@PathVariable("id") long id,Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{ //...... code.......
return "myPage";
}
@RequestMapping("/test.do")
public String saveAddressCompany(Map<String, Object> map, @ModelAttribute("company")
Company company,@ModelAttribute("address")
CompanyAddress address, BindingResult result)
{ //...... code.......
return "myPage";
}
目的:
提交第一表單,其存在於DIV A I希望啓用的div B,其將包含另一種形式之後。
問題:
第一種形式是正確提交,但是當我點擊提交的第二種形式按鈕,它也會引發異常(行動甚至沒有得到所謂的)
例外:
無法將值測試從類型'java.lang.String'轉換爲類型'long';嵌套異常是java.lang.NumberFormatException:對於輸入字符串:「test」]有根本原因
任何想法....?
在此先感謝... !!!
看起來你的test.do被註解爲@RequestMapping(「/ companyAddressPage/{id} .do」)的方法所處理,並且自從值爲「test」的{id}部分出現解析錯誤, (不含引號)不能被解析爲很長時間。用@RequestMapping(「/ test.do」)註解的@ModelAttribute(「company」)方法是有意的嗎? – heikkim
其實我有兩個模型屬性的地址和公司,在公司我有公司代碼,這是常見的地址也 – JOHND
爲什麼它調用/companyAddressPage/{id}.do,我打電話test.do提交行動的第二種形式 – JOHND