我使用mvc spring作为表格。 一切正常,但我总是
@ModelAttribute EncondingModel encodingTABnet
为null。 当我看一下Ajax Call
$('#encoding_form&#39)。序列()
它有这个价值:
"密码= asdfasdf&安培;键= asdfasdfasdfasdfasdf"
但在我的控制器中,Model始终为null。 有人能帮我找到问题吗?
Form.jsp:
<form:form id="encoding_form" modelAttribute="encodingTABnet" commandName="encodingTABnet" name="form-encoding-do">
<form:input cssClass="password" type="text" placeholder="Passwort Plain" path="password"/>
<form:input cssClass="key" type="text" placeholder="Secret Key" path="key"/>
<br>
<button type="button" class="btn" onclick="${ns}calculateForm()"><i class="tab-icon tab-icon-ok">Start encoding</i></button>
<div class="error-message"></div>
</form:form>
view.jsp的
<portlet:actionURL var="calculatePasswordAjaxURL" windowState="EXCLUSIVE">
<portlet:param name="action" value="calculateForm"/>
</portlet:actionURL>
<script>
function ${ns}calculateForm() {
$.post("${calculatePasswordAjaxURL}", $('#encoding_form').serialize(), function (data) {
container.html(data);
});
}
</script>
控制器:
@RenderMapping(params = "action=showForm")
public String showFormView(Model model, RenderRequest request, RenderResponse response) throws Exception {
return ENCODING_FORM;
}
@ActionMapping(params = "action=showForm")
public void showForm(ActionRequest request, ActionResponse response, Model model) throws Throwable {
final EncodingModel encoding = new EncodingModel();
model.addAttribute("encodingTABnet", encoding);
response.setRenderParameter("action", "showForm");
}
@ActionMapping(params = "action=calculateForm")
public void calculatePassword(@ModelAttribute EncodingModel encodingTABnet, BindingResult result,
ActionRequest actionRequest, ActionResponse actionResponse,
Model model, SessionStatus status) {
allstuff = new AllStuff();
allstuff.setKey(encodingTABnet.getKey());
allstuff.setPassword(encodingTABnet.getPassword());
allstuff.setEncode(aes.encrypt(encodingTABnet.getPassword(), encodingTABnet.getKey()));
status.setComplete();
actionResponse.setRenderParameter("action", "showContent");
}
类别:
public class EncodingModel {
private String password;
private String key;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}