<div>
<input name="wordCount" type="text"/>
<input type="submit" name="start" value="Start" onclick=""/>
</div>
当我点击“开始”时按钮,我想从控制器访问此输入值。但是,我不想使用表单标签。我可以使用Javascript设置为会话值吗?如果是,我该怎么办?感谢名单。
答案 0 :(得分:0)
You can use an ajax call to send your data to a controller.
<强> HTML 强>
<div>
<input name="wordCount" id="wordCount" type="text"/>
<input type="submit" name="start" value="Start" onclick="ajaxCall()"/>
</div>
<强> JQuery的强>
function ajaxCall() {
var value = $('#wordCount').val();
$.ajax({
type : 'POST',
url : 'controller.htm',
data:{value:value},
success : function(data) {
alert('Success');
}
});
}
<强>控制器强>
@RequestMapping(value="/controller" ,method = RequestMethod.POST)
@ResponseBody
public String restructure(Model model, HttpSession session, HttpServletResponse response, final RedirectAttributes redirectAttributes,
@RequestParam(value = "value",required=false) String value){
System.out.println("Value from JSP "+ value);
}
希望有所帮助:)