`

response.setContentType 的设置

    博客分类:
  • J2EE
阅读更多

Sets the Content-Type header. Content-Type identifies the MIME type of the response document and the character set encoding.
To set the Content-Type header, use the following code:
response.setContentType("text/html; charset=gbk");
The default MIME type is text/plain. Some common MIME types include:

 

------------------------------------------------------------------
HTML format (.htm or .html): text/html
Adobe Portable Document (pdf): application/pdf
Microsoft Word (.doc): application/msword
Microsoft Excel (.xls): application/msexcel
Microsoft Powerpoint (.ppt): application/ms-powerpoint
Realaudio (.rm, .ram): audio/x-pn-realaudio
Text format (.txt): text/txt
Zipped files (.zip): application/zip

 

response.setContentType( "application/msword" );
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-type","application/pdf");

分享到:
评论

相关推荐

    response.setContentType

    response.setContentType()中有关文件上传的种类说明。

    response.setContentType()的作用及MIME参数详解

    response.setContentType(MIME)的作用是使客户端浏览器,区分不同种类的数据,并根据不同的MIME调用浏览器内不同的程序嵌入模块来处理相应的数据。 例如web浏览器就是通过MIME类型来判断文件是GIF图片。通过MIME类型...

    将数据导出到Excel

    将数据导出到Excel源代码及方法:response.setContentType("application/vnd.ms-excel");//响应正文的MIME类型,表示Excel response.addHeader("Content-Disposition", "attachment;filename=logininfo.xls"); ...

    JSP 中response.setContentType()的作用及参数

    JSP 中response.setContentType()的作用及参数 response.setContentType(MIME)的作用是使客户端浏览器,区分不同种类的数据,并根据不同的MIME调用浏览器内不同的程序嵌入模块来处理相应的数据。 例如web浏览器...

    JSP中response.setContentType和response.setCharacterEncoding区别分析

    主要介绍了JSP中response.setContentType和response.setCharacterEncoding区别分析,较为详细的分析了response.setContentType和response.setCharacterEncoding的功能与具体使用技巧,需要的朋友可以参考下

    用户管理系统(ums)

    response.setContentType("text/html;charset=GB18030"); response.setCharacterEncoding("GB18030"); request.setCharacterEncoding("GB18030"); //调用业务逻辑 UserDAO userDAO = new UserDAO(); // ...

    随机验证码源代码详解

    //response.setContentType(CONTENT_TYPE); response.setContentType("image/jpeg"); //设置浏览器不要缓存此图片 response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "on-cache...

    response.getWriter().write()向前台打印信息乱码问题解决

    response.getWriter().write() 功能:向...response.setContentType(text/html;charset=UTF-8); response.getWriter().write(在此处传递要显示的内容!); 您可能感兴趣的文章:对python中的iter()函数与next()函数详解P

    anmo_mybatis_generator.zip

    public void code(HttpServletRequest request, HttpServletResponse response) ... response.setContentType("application/octet-stream; charset=UTF-8"); IOUtils.write(data, response.getOutputStream()); }

    MIME类型大全(response.setContentType中MIME参数类型总结)

    MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开。多用于指定一些客户端自定义的文件名,以及一些媒体文件打开方式

    swing导出Excel

    response.setContentType("application/msexcel"); response.setHeader("Content-disposition","attachment; filename=clerkAddress.xls"); WritableWorkbook workbook = Workbook.createWorkbook(os); ...

    Ireport强大的报表工具制作报表必用代码 在Servlet中将集合中的数据输出到PDF,XLS,HTML

    response.setContentType("application/pdf"); JRBeanCollectionDataSource jbcd = new JRBeanCollectionDataSource(list); try { JasperPrint jr = JasperFillManager.fillReport(new FileInputStream("C:\\...

    proxool-0.9.1.jar

    发现果然没有做response的字符设置。 在doGet(HttpServletRequest request, HttpServletResponse response)方法里加入了一句response.setContentType("text/html;charset=GBK");解决了在utf-8编码下的中文乱码问题。...

    验证码下载,验证码实现

    response.setContentType("image/jpeg"); //禁止浏览器缓存 response.addHeader("pragma", "NO-cache"); response.addHeader("Cache-Control", "no-cache"); response.addDateHeader("Expries", 0); //...

    Jackson的jar包

    1、JackSon使用Java类中的getxxx()方法定位生成的json对象... response.setContentType("application/json;charset=utf-8"); response.getWriter.print(json); 或者 mapper.writeValue(Writer out,Object param);

    批量打包下载

    response.setContentType("application/x-download");// 设置response内容的类型 response.setHeader( "Content-disposition", "attachment;filename=" + URLEncoder.encode(str, "UTF-8"));// 设置头部...

    什么是软件测试ppt

    介绍软件测试培训的PPT private void collect... response.setContentType("text/xml"); ServletOutputStream out=response.getOutputStream(); out.write(buffer.toString().getBytes("UTF-8")); out.close(); }

Global site tag (gtag.js) - Google Analytics