java web中,重写response应答体(响应体)
/*** * Send http request * * @param response * @param bytes :字节数组 * @param contentType :if is null,default value is "application/json" * @param encoding : 编码方式 * @throws IOException */ public static void sendRequestWriter(HttpServletResponse response, byte[] bytes, String contentType,String encoding) throws IOException { response.setContentLength(bytes.length); if (contentType == null) { contentType = "application/json"; } response.setContentType(contentType); PrintWriter printer = response.getWriter(); printer.println(new String(bytes,encoding)); printer.flush(); printer.close(); } /*** * * @param response * @param sendData :<code>String</code> * @param contentType * @param encoding : such as GBK/utf-8 * @throws IOException */ public static void sendRequestWriter(HttpServletResponse response, String sendData, String contentType,String encoding) throws IOException { // response.setContentLength(sendData.getBytes(encoding).length); byte[]bytes=sendData.getBytes(encoding); sendRequestWriter(response, bytes, contentType, encoding); }
以上方法都是使用PrintWriter来写入response的。
下面的方式是使用流的方式写入response:
/*** * test ok * @param response * @param bytes * @param contentType * @param encoding * @throws IOException */ public static void sendRequestStream(HttpServletResponse response, byte[] bytes, String contentType) throws IOException { response.setContentLength(bytes.length); if (contentType == null) { contentType = "application/json"; } response.setContentType(contentType); ServletOutputStream sos = response.getOutputStream(); sos.write(bytes, 0, bytes.length); sos.flush(); sos.close(); }
应用:用于在网关中进行请求转发和响应。
见附件中的类com.common.util.SystemUtil
相关推荐
重写了servlet能实现乱码过滤,并能屏蔽敏感字符!
在很多情况下,WEB中进行URL重写一般是使用WEB服务器自身提供的组件。开源项目Url Rewrite Filter ,使用Filter来完成这项工作,从而不依赖于WEB服务器组件。
ajax重写方法搭配后台filter返回status实现ajax请求跳转登录页面
Filter中的模糊过滤: 要实现模糊过滤,BDE中要用“*”,不允许使用“Like”关键字,且只能向后匹配,如“Fcode=’101*’”;而ADO则是使用“%”或“*”都可以,可以使用“Like”关键字,且和SQL语句用法一致,可以...
博文https://blog.csdn.net/yy417168602/article/details/80497664的工程附件
java中filter的用法(过滤器),介绍各种过滤方法
因为需要使用filter函数(MATLAB内置函数),曾在网上copy过一段代码,但是那个算法实现的不全,没有计算zf,所以我自己结合MATLAB帮助重写了一下,测试结果OK
C语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC语言头文件 FILTERC...
XSS是一种经常出现在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到提供给其它用户使用的页面中。比如这些代码包括HTML代码和客户端脚本。攻击者利用XSS漏洞旁路掉访问控制——例如同源策略(same origin...
对request请求进行拦截,... <filter-class>weixin.idea.waiting.cq.controller.JsFilter</filter-class> </filter> <filter-mapping> <filter-name>sqlFilter</filter-name> <url-pattern>/* </filter-mapping>
FilterPro低通滤波器设计软件及中文使用资料,用于设计滤波器,放大器
配置Filter过滤器处理JSP中文乱码 参考Tomcat服务器目录webapps的examples示例 简单配置步骤: 1.在项目web.xml文件添加过滤器标记<filter>和<filter-mapping>; 2.实现过滤器代码; 3.对Tomcat服务器conf目录里的...
git filter-repo是用于重写历史记录的多功能工具,其中包括。 它与大致属于同一工具领域,但是没有引起下降的缺点,具有更多的功能,并且其设计在可用性方面超出了琐碎的重写案例。 而不是git filter-branch。 尽管...
视频中工程代码 class9_key_filter视频中工程代码 class9_key_filter视频中工程代码 class9_key_filter视频中工程代码 class9_key_filter视频中工程代码 class9_key_filter视频中工程代码 class9_key_filter视频中...
叙述了MATLAB中几种相关函数的用法,对filter conv 和impz函数进行了介绍
Filter中文乱码问题.doc
Css中的filter属性语法说明.Css中的filter属性语法说明.Css中的filter属性语法说明.
FilterPro 安装及基本教程中英文 对有源滤波器设计的一款TI官方的设计软件及中英文的使用说明 sallen-key及多反馈 (MFB)设计参考
Filter Drivers主要包括以下特性: 1) 一个Filter Drivers实例叫Filter Module。Filter Module附加在一个适配器的微端口驱动上, 来自相同或不同Filter Drivers的多个Filter Module都可以被堆叠在一个网络...