异步上传图片的代码。发现里面用了response.getWriter().print(),故联想到response.getWriter().writer(),经过一番api的查找与实操,总结如下:
<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#button1").click(function(){ $.get("AJAXServer",null,function(data){ alert(data); $("#info").html(data); }); }); }) </script> </head> <body> <input type="button" id="button1" value="点我获取服务器响应信息" onclick="a()";/> <div id="infd
输出对象服务器端代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Person person = new Person(); person.setName("sjl"); response.getWrier().print(person);}
运行结果 :
server.Person@5bd5ab
如果使用response.getWriter().writer(),则代码会报错
演示文本信息的服务器端代码:
response.getWriter().write("this is <b>server</b> response"); /**response.getWriter().print("this is<b>server2</b>response")*/;
输出结果
this is server response
注释的代码输出效果一样
response.getWriter().write()和 response.getWriter().print()的区别
原文:http://www.cnblogs.com/qlqwjy/p/7455706.html