It is important to note the related configuration items in the Spring-mvc.xml (Spring controller configuration file)
<!--scan only @controller---<context:component-scan base-package= " Cn.com.sunnyrock.vimes.portal "use-default-filters=" true "> <context:include-filter type=" Annotation " expression= "Org.springframework.stereotype.Controller"/> </context:component-scan> <!--encoding conversion, Its tacit view iso-8859-1--> <bean class= " Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "> <property name=" Cacheseconds "value=" 0 "/> <property name=" messageconverters "> <list> <bean CL "Org.springframework.http.converter.StringHttpMessageConverter" > <property name = "Supportedm Ediatypes "> <list> <value>text/html;charset=utf-8</val ue> </list> </property> </bean> </l Ist> </property> </bean>
<!--annotation automatic injection, this configuration is important--
<bean class= " Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "/>
<!--must remove this configuration item <mvc:annotation-driven/>--
The method in the controller
@RequestMapping (value = "/feedback", method = requestmethod.post) public
@ResponseBody
String Feedback ( HttpServletRequest request, HttpServletResponse response, Feedbackmodel feedback) throws exception{
//todo
Return "Thank you very much for your valuable comments or suggestions to us";
}
Ajax calls in JSPs (Jquery.form.js This plugin is used here)
var feedbackadviceform = "#feedbackAdviceForm";
$ (Feedbackadviceform). Submit (function () {
if ($.trim ($ ("#advice", Feedbackadviceform). val ()) = = "") {
alert ( "Please input your valuable comments or suggestions." ");
$ ("#advice", Feedbackadviceform). focus ();
return false;
}
$ (this). Ajaxsubmit ({
success:function (msg) {
alert (msg);
},
error:function (context, XHR) {
alert (context.responsetext);});
});
<form id= "Feedbackadviceform" name= "Feedbackadviceform" action= "<%=rootpath%>/member/feedback.html" Method= "POST" onsubmit= "return false;" >
<p>
<label for= "Advice" > Please enter your valuable comments or suggestions </label><br>
<textarea id= " Advice "name=" advice "rows=" 3 "cols=" style= "width:200px; height:120px; " ></textarea>
</p>
<p>
<input type= "Submit" value= "Submission" >
</p>
</form>