是否可以在沒有刷新的情況下在SPRING MVC 3中提交表單?無刷新提交表單(SPRING MVC 3)
我想要的是將數據以SPRING形式存儲到java object/POJO。
這裏是我的map.jsp
<form:form action="" method="post" commandName="userQuery">
<form:input path="startLocation" id ="startLocation" />
<input type="submit" value="Search" onclick="codeAddress()">
<script type="text/javascript">
function codeAddress(){
var address = document.getElementById("startLocation").value;
geocoder.geocode({ 'address': address, 'partialmatch' : true }, geoCodeResults);
</script>
我想的數據(即startLocation)存儲Java對象,在同一時間使用的是JavaScript的數據,所以我可以顯示谷歌地圖並在該位置顯示標記。但我每次提交表單時,它刷新頁面,於是,該標記不呈現,因爲它重新加載整個頁面,包括地圖
這裏是我的Controller.java
@RequestMapping(value= "/map" , method = RequestMethod.GET)
public ModelAndView showMap(){
ModelAndView mav = new ModelAndView("home/map");
Query query = new Query();
mav.getModel().put("userQuery", query);
return mav;
}
@RequestMapping(value="/map", method = RequestMethod.POST)
public ModelAndView createMap(@ModelAttribute("userQuery") Query query){
ModelAndView mav = new ModelAndView("home/map");
List<Query> q = new ArrayList<Query>();
q.add(new Query(query.getStartLocation()));
mav.addObject("q", q);
return mav;
}
我需要存儲startLocation。請幫忙。除了SPRING表單之外,還有其他方法可以存儲用戶輸入嗎?