前后端数据传递

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenshibailian/article/details/79896610
HttpServletRequest request;

HttpServletResponse response;

前后端数据的传递主要是通过以上连个接口,通过浏览器将前端的请求,打包通过request传递给后台服务器。

后台的数据同样打包通过response响应给前端。

例如:将数据响应给前端。

               response.setCharacterEncoding("UTF-8");设置字符集
response.setContentType("text/html");设置响应文本格式,告诉浏览器要接受的数据类型。
PrintWriter pw=response.getWriter(); 输出流,
try{
pw.print(str); 通过输出流将内容传递过去
}finally{
pw.flush(); 将pw中的剩余的字节传递过去
pw.close(); 关闭流

}

前端的表单内容,在后台接受的方法:

String param = request.getTextParam("input的name值"); 获取单name属性个值

String[] params= request.getParameterValues("name值"); name属性相等的多个值

猜你喜欢

转载自blog.csdn.net/chenshibailian/article/details/79896610
今日推荐