servlet-响应信息的content-Type作用
package servlet; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 案例- content-Type作用
* @author Administrator
*
*/
public class ResponseDemo4 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { /*
* 设置响应实体内容编码
*/
response.setCharacterEncoding("utf-8"); /*
* 1. 服务器发送给浏览器的数据类型和内容编码
*/
// response.setHeader("content-type", "text/html");
response.setContentType("text/html; charset=utf-8");//和上面代码等价。推荐使用此方法 //response.getWriter().write("<html><head><title>this is tilte</title></head><body>中国</body></html>");
response.getOutputStream().write("<html><head><title>this is tilte</title></head><body>中国</body></html>".getBytes("UTF-8")); File file = new File("D:\\linux\\files Structure.png"); // 设置以 下载 方式打开文件
response.setHeader("content-Disposition", "attachment; filename=" + file.getName()); // 发送图片
FileInputStream in = new FileInputStream(file);
byte[] buf = new byte[1024];
int len = 0; // 把图片内容写出到浏览器
while ( (len = in.read(buf)) != -1) {
response.getOutputStream().write(buf, 0, len);
} } }
servlet-响应信息的content-Type作用的更多相关文章
- php 下载文件的头信息 Determine Content Type
<?php if(!function_exists('mime_content_type')) { function mime_content_type($filename) { $mime_t ...
- 转载 SharePoint【Site Definition 系列】– 创建Content Type
转载原地址: http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...
- Spring Boot使用AOP在控制台打印请求、响应信息
AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事务,权限等. AOP简介 AOP全称Aspect Oriented Programming,面向切面,AOP主要实现的 ...
- openresty(完整版)Lua拦截请求与响应信息日志收集及基于cjson和redis动态路径以及Prometheus监控(转)
直接上文件 nginx.conf #运行用户和组,缺省为nobody,若改为别的用户和组,则需要先创建用户和组 #user wls81 wls; #开启进程数,一般与CPU核数等同 worker_pr ...
- jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported"的解决方法
1.报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supporte ...
- Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决
Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决 引言: 在Java中 ...
- org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
最后找到我的问题,springmvc配置文件中没加 <mvc:annotation-driven/> java代码: @RequestMapping(value="/reques ...
- JavaWeb基础(day15)( http + tomcat + servlet + 响应)
HTTP+Tomcat+Servlet+响应 HTTP HTTP 超文本传输协议(Hyper Text Transfer Protocol ),一种网络协议. 协议的组成和过程 HTTP协议由 ...
- day112:MoFang:种植园使用websocket代替http&服务端基于flask-socketio提供服务&服务端响应信息&种植园页面显示初始化
目录 1.种植园使用websocket代替http 2.服务端基于socket提供服务 3.服务端响应信息 4.种植园页面展示 1.种植园使用websocket代替http 我们需要完成的种植园,是一 ...
- Content type 'application/json;charset=UTF-8' not supported异常的解决过程
首先说一下当时的场景,其实就是一个很简单的添加操作,后台传递的值是json格式的,如下图 ,后台对应的实体类, @Data @EqualsAndHashCode(callSuper = false) ...
随机推荐
- 20181010关于pt-kill自动杀死运行超长的进程
转自: http://blog.chinaunix.net/uid-16844903-id-4442030.htmlhttp://blog.chinaunix.net/uid-31396856-id- ...
- ORACLE分区表删除分区数据
--全删除 ALTER TABLE tableName DROP PARTITION partionName UPDATE GLOBAL INDEXES; --清数据 ALTER TABLE tabl ...
- nyoj_79_拦截导弹_201403182040
拦截导弹 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 某国为了防御敌国的导弹袭击,发展中一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到 ...
- CentOS 7: 配置Network
Command Mode Step 1 » Network interface config files are located in /etc/sysconfig/network-scripts/ ...
- Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistr ...
- 服务器Hot Spare热备
Hot Spare:热备用 当一个正在使用的磁盘发生故障后,一个空闲.加电并待机的磁盘将马上代替此故障盘,此方法就是热备用.热备用磁盘上不存储任何的用户数据,最多可以有8个磁盘作为热备用磁盘.一个热备 ...
- 使用SQL Profile及SQL Tuning Advisor固定运行计划
SQL Profile就是为某一SQL语句提供除了系统统计信息.对象(表和索引等)统计信息之外的其它信息,比方执行环境.额外的更准确的统计信息,以帮助优化器为SQL语句选择更适合的执行计划. SQL ...
- Effective C++ Item 44 将与參数无关的代码抽离 templates
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie 经验:Templates 生成多个 classes 和多个函数,所以不论什么 templat ...
- hdu5305(2015多校2)--Friends(状压,深搜)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 进销存管理系统, 刚学C++
各位大神们.有什么补充的能够评论一下吗? #include<iostream> #include<string> using namespace std; int G=0;// ...