spring mvc 和jsp传值问题
我把这个form表单提交到控制器
<form action="" id="discuss_form" name="discuss_form">
<input type="hidden" value="${ytvVideo.id }" name="videoId" id="videoId"/>
<textarea rows="5" cols="80" name="discuss" id="discuss"></textarea>
<input type="button" id="discuss_submit" value="提交" />
</form>
通过ajax提交
$(function(){
$("#discuss_submit").click(function(){
$.ajax({
type: "GET",
url: "/ytv/video/savediscuss",
data: $("#discuss_form").serializeArray(),
success: function(data){
alert(data);
if(data.status==1){
alert(data.message)
}if(data.status==0){
alert(data.message)
}if(data.status2==2){
alert(data.discuss)
}
}
});
});
});
控制器
@RequestMapping(value = "/savediscuss", method = RequestMethod.GET)
public Map<String, Object> savadiscuss(HttpServletRequest request,
@RequestParam String discuss, HttpSession session,
@RequestParam Integer videoId) {
Map<String, Object> msg = new HashMap<String, Object>();
YtvUser ytvUser = (YtvUser) session.getAttribute(YtvUser.LOG_NAME);
if (ytvUser == null) {
msg.put("status", 2);
msg.put("message", "你先登录再进行评论,谢谢");
} else {
try {
YtvDiscuss ytvDiscuss = new YtvDiscuss();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String createDateTime = sdf.format(new Date());
ytvDiscuss.setCreateDateTime(createDateTime);
ytvDiscuss.setDiscuss(discuss);
ytvDiscuss.setUserId(ytvUser.getId());
ytvDiscuss.setVideoId(videoId);
ytvDiscussService.createYtvDiscuss(ytvDiscuss);
msg.put("status", 1);
msg.put("message", "评论成功");
} catch (Exception e) {
e.printStackTrace();
msg.put("status", 0);
msg.put("message", "评论失败");
System.out.println("出现异常了!!");
}
}
return msg;
}
}
问题是,msg返回不到jsp页面!!!求解!!!
------解决方案--------------------页面jquery有$.getJSON()吧,
是不是还要在方法上加@responseBody