<script src="<%=basePath%>/js/jquery-2.1.1.js"></script>
<script type="text/javascript"> function btn_click() { $.ajax( { type : "POST", url : "/welcome", data : { 'room' : '123qwe', 'roomid' :'abcdefg' }, dataType: "json", success : function(data) { if(data.success){ alert("设置成功!"); document.getElementById("info").innerText='ajax123m'; } else{ alert("设置失败!"); } }, error :function(){ alert("网络连接出错!"); } }); } </script>
<mvc:resources mapping="/js/**" location="/js/" />
@RequestMapping(value = "/welcome", method = RequestMethod.POST ) public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // String roomid= request.getParameter("roomid"); // String room= request.getParameter("room"); //session.setAttribute("ROOMID", roomid); //session.setAttribute("ROOMNAME", room); // System.out.println("session set:"+room+"=="+roomid); response.setCharacterEncoding("utf-8"); response.getWriter().write("{\"success\":true }"); response.getWriter().flush(); }