序列化 ObjectMapper om = new ObjectMapper(); om.writerWithDefaultPrettyPrinter().writeValueAsString(userList);返回字符串类型 返序列化 ?ServletInputStream inputStream = req.getInputStream(); ?// 输入流 ObjectMapper om = new ObjectMapper(); ?// 不带泛型,我们不知道实际是什么类型 HashMap map = om.readValue(inputStream, HashMap.class); SomeClass o = om.readValue(inputStream, SomeClass.class);
js中 发送请求:XMLHttpRequest open(“GET”“url”)(绑定),onload(在响应成功时执行),responseText(响应体文本),send(发送请求) JSON.paese(xml.responseText) ? 将序列化字符串转化为数组 JSON.stringify() ?将JS对象序列化
open("post","url") setRequestHeader("Content-Type","appliction/json"); ?请求体的类型是JSON格式 send(data) ?把data作为响应体发送出去
重定向 resp.setStatus(302); resp.setHeader("locatuin","url"); == resp.sendRedirect("url");
req.getRequestDispatcher("url").forward(req,resp); ?
|