springmvc controller怎么获取一个输入流
答案:1 悬赏:0 手机版
解决时间 2021-03-10 03:10
- 提问者网友:箛茗
- 2021-03-09 19:19
springmvc controller怎么获取一个输入流
最佳答案
- 五星知识达人网友:一把行者刀
- 2021-03-09 19:37
springmvc 中controller获取ajax数据的方法:<br>1、页面jsp代码:<br><table style="width: 100%" class="table" cellspacing="1" cellpadding="1" border="0"><br> <tr><td class="ti1" colSpan="2">请选择审讯室</td></tr> <br> <tr><td class="ti2hui">审讯室名称</td><td class="ti1cu"><br> <select id="roomid" name="roomid" ><br> <c:forEach items="${roomlist}" var="room"> <br> <option value ="${room.id}">${room.name}</option> <br> </c:forEach><br> </select><br> </td></tr><br><tr><td class="ti2hui" colSpan="2" align="center"><input type="button" onclick="setshow()" value="确定"/> </td></tr><br></table><br>点击确定后触发ajax接口:<br>function setshow(){ <br>$.ajax( { <br> type : "POST", <br> url : "<%=request.getContextPath()%>/initroom.do?method=set", <br> data : {<br> 'room' : $("#roomid").find('option:selected').text(),<br> 'roomid' :$("#roomid").val()<br> }, <br> dataType: "json", <br> success : function(data) { <br> if(data.success){ <br> alert("设置成功!"); <br><br> } <br> else{ <br> alert("设置失败!"); <br> } <br> }, <br> error :function(){ <br> alert("网络连接出错!"); <br> } <br>}); <br>} <br>2、后台controller写法: <br>@RequestMapping(params = "method=set")<br> public void jump(HttpSession session,HttpServletRequest request, HttpServletResponse response) throws Exception{<br> String roomid= request.getParameter("roomid");<br> String room= request.getParameter("room");<br> session.setAttribute("ROOMID", roomid);<br> session.setAttribute("ROOMNAME", room);<br> System.out.println("session set:"+room+"=="+roomid);<br> response.setCharacterEncoding("utf-8");<br> response.getWriter().write("{\"success\":true }");<br> response.getWriter().flush();<br> }<br>3、springmvc 返回信息到ajax:<br>import com.googlecode.jsonplugin.JSONUtil;<br>List<Records> recordList = new ArrayList<Records>();<br>//获取recordlist操作省略<br> response.setCharacterEncoding("utf-8");<br> response.getWriter().write("{\"success\":true, \"data\":" + JSONUtil.serialize(recordList) + "}");<br> response.getWriter().flush();
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯