关于 reponse 返回类型 contentType 是 application/json;charset=ISO-8859-1 现象的阐述 现象发生描述: 在 Interceptor 的 preHandle 方法对 response 设置 contentType和charset response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.setCharacterEncoding ("UTF-8"); 之后,发现了浏览器F12页面中的请求结果的 responseHeader 中 contentType 属性始终是 application/json;charset=ISO-8859
现象:使用postman测试响应ContentType没有值 这是我的部分代码: @Override public void download(Long buildingId, HttpServletResponse
json 的 contentType 常见写法有 : text/json & text/javascript . 对于json的contentType , rfc里定义的标准写法是 :application/json. 如果没有设置 contentType 客户端很难判断 返回的数据是什么, 该怎么处理. ========================== 另外,对于返回信息,如果不设置contentType,web 服务器往往会给返回的内容添加一个”默认的contentType”, 但是这个”默认”会根据服务器的不同 以及web应用配置的不同而不同. 所以 正确设置返回信息的 contentType 还是很有必要的. ====================== 总结 & 建议 : 1.
contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中。 那么这个表有什么作用呢? 只需要以下三步: 在model中定义ForeignKey字段,并关联到ContentType表。 示例代码: from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields 1 """ name = models.CharField(max_length=32) content_type = models.ForeignKey(to=ContentType GenericForeignKey('content_type', 'object_id') # step 3 def __str__(self): return self.name 注意:ContentType
在django中,有一个记录了项目中所有model元数据的表,就是ContentType,表中一条记录对应着一个存在的model,所以可以通过一个ContentType表的id和一个具体表中的id找到任何记录 1.ContentType.model_class(): 获取当前ContentType类型所代表的模型类。 2.ContentType.get_object_for_this_type(): 使用当前ContentType类型所代表的模型类做一次get查询。 ? 3.ContentType.objects.get_for_id(): 通过id寻找ContentType类型,这个跟传统的get方法的区别就是它跟get_for_model共享一个缓存。 4.ContentType.objects.get_for_model(): 通过model或者model的实例来寻找ContentType类型。 ?
一、ContentType 在django中,有一个记录了项目中所有model元数据的表,就是ContentType,表中一条记录对应着一个存在的model,所以可以通过一个ContentType表的 也就是说,今后,我们如果自己定义model如果有外键关联到這个ContentType上,我们就能找到对应的model名称。 为此,我们可以利用Django自带的ContentType类,来做这件事情。 一般命名为“content_type”.用来放想要关联的那个表在contenttype表中的id content_type = models.ForeignKey(ContentType, blank 总之,如果一个表与其他表有多个外键关系,我们可以通过ContentType来解决这种关联。
Response.ContentType 详细列表 不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式. 代码如: <% response.ContentType =”text/html” %> <! –#i nclude virtual=”/ContentType.html” –> 显示的为网页,而 <% response.ContentType =”text/plain” %> –#i nclude virtual=”/sscript/ContentType.html” –> 则会显示html原代码. 以下为一些常用的 ContentType GIF images <% response.ContentType =”image/gif” %> <!
大家好,又见面了,我是你们的朋友全栈君。‘ez’ => ‘application/andrew-inset’, ‘hqx’ => ‘application/mac-binhex40’, ‘cpt’ => ‘application/mac-compactpro’, ‘doc’ => ‘application/msword’, ‘bin’ => ‘application/octet-stream’, ‘dms’ => ‘application/octet-stream’, ‘lha’ => ‘application/octet-stream’, ‘lzh’ => ‘application/octet-stream’, ‘exe’ => ‘application/octet-stream’, ‘class’ => ‘application/octet-stream’, ‘so’ => ‘application/octet-stream’, ‘dll’ => ‘application/octet-stream’, ‘oda’ => ‘application/oda’, ‘pdf’ => ‘application/pdf’, ‘ai’ => ‘application/postscript’, ‘eps’ => ‘application/postscript’, ‘ps’ => ‘application/postscript’, ‘smi’ => ‘application/smil’, ‘smil’ => ‘application/smil’, ‘mif’ => ‘application/vnd.mif’, ‘xls’ => ‘application/vnd.ms-excel’, ‘ppt’ => ‘application/vnd.ms-powerpoint’, ‘wbxml’ => ‘application/vnd.wap.wbxml’, ‘wmlc’ => ‘application/vnd.wap.wmlc’, ‘wmlsc’ => ‘application/vnd.wap.wmlscriptc’, ‘bcpio’ => ‘application/x-bcpio’, ‘vcd’ => ‘application/x-cdlink’, ‘pgn’ => ‘application/x-chess-pgn’, ‘cpio’ => ‘application/x-cpio’, ‘csh’ => ‘application/x-csh’, ‘dcr’ => ‘application/x-director’, ‘dir’ => ‘application/x-director’, ‘dxr’ => ‘application/x-director’, ‘dvi’ => ‘application/x-dvi’, ‘spl’ => ‘application/x-futuresplash’, ‘gtar’ => ‘application/x-gtar’, ‘hdf’ => ‘application/x-hdf’, ‘js’ => ‘application/x-javascript’, ‘skp’ => ‘application/x-koan’, ‘skd’ => ‘application/x-koan’, ‘skt’ => ‘application/x-koan’, ‘skm’ => ‘application/x-koan’, ‘latex’ => ‘application/x-latex’, ‘nc’ => ‘application/x-netcdf’, ‘cdf’ => ‘application/x-netcdf’, ‘sh’ => ‘application/x-sh’, ‘shar’ => ‘application/x-shar’, ‘swf’ => ‘application/x-shockwave-flash’, ‘sit’ => ‘application/x-stuffit’, ‘sv4cpio’ => ‘application/x-sv4cpio’, ‘sv4crc’ => ‘application/x-sv4crc’, ‘tar’ => ‘application/x-tar’, ‘tcl’ => ‘application/x-tcl’, ‘tex’ => ‘application/x-tex’, ‘texinfo’ => ‘application/x-texinfo’, ‘texi’ => ‘application/x-texinfo’, ‘t’ => ‘application/x-troff’, ‘tr’ => ‘applica
contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中。 只需要以下三步: 在model中定义ForeignKey字段,并关联到ContentType表。 示例代码:models.py文件: from django.db import models from django.contrib.contenttypes.models import ContentType def __str__(self): return self.name 注意:ContentType只运用于1对多的关系!!!并且多的那张表中有多个ForeignKey字段。 def test(request): if request.method == 'GET': # ContentType表对象有model_class() 方法,取到对应model
在ASP.NET中,设定MIME类型的方法是通过Response对象的ContentType属性。 response的contentType ajax开发中在请求服务器端的响应时, 对于每一种返回类型 规范的做法是要在服务端指定response的contentType 的. text/xml” 4 、服务端需要返回一段javascript代码给客户端,text/javascript 5 、服务端需要返回一段json串给客户端,application/Json 比较全面的contentType
application/activemessage application/andrew-inset application/applefile application/atomicmail application/dca-rft application/dec-dx application/mac-binhex40 hqx application/mac-compactpro cpt application/macwriteii application/msword doc application/news-message-id application/news-transmission application/octet-stream bin dms lha lzh exe class application/jsp jsp application/oda oda application/pdf pdf application/postscript ai eps ps application/powerpoint ppt application/remote-printing application/rtf rtf application/slate application/wita application/wordperfect5.1 application/x-bcpio bcpio application/x-cdlink vcd application/x-compress Z application/x-cpio cpio application/x-csh csh application/x-director dcr dir dxr application/x-dvi dvi application/x-gtar gtar application/x-gzip gz application/x-hdf hdf application/x-httpd-cgi cgi application/x-java-jnlp-file jnlp application/x-koan skp skd skt skm application/x-latex latex application/x-mif mif application/x-netcdf nc cdf application/x-sh sh application/x-shar shar application/x-stuffit sit application/x-sv4cpio sv4cpio application/x-sv4crc sv4crc application/x-tar tar application/x-tcl tcl application/x-tex tex application/x-texinfo texinfo texi application/x-troff t tr roff application/x-troff-man man application/x-troff-me me application/x-troff-ms ms application/x-ustar ustar application/x-wais-source src text/xml XML ent cat sty text/dtd dtd text/xsl xsl application/jsp jsp application/zip zip audio/basic au snd audio/mpeg mpga mp2 audio/x-aiff aif aiff aifc audio/x-pn-realaudio ram audio/x-pn-realaudio-plugin rpm audio/x-realaudio ra audio/x-wav wav chemical/x-pdb pdb xyz image/gif gif image/ief ief image/jpeg jpeg jpg jpe image/png png image/tiff tiff tif image/x-cmu-raster ras image/x-portable-anymap pnm image/x-portable-bitmap pbm image/x-portable-graymap pgm image/x-portable-pixmap ppm image/x-rgb rgb image/x-xbitmap xbm image/x-xpixmap xpm image/x-xwindowdump xwd message/external-body message/news message/partial message/rfc822 multipart/
(HTTP)常见请求头、响应头、ContentType整理 请求头 请求头 说明 Accept 浏览器支持的 MIME 媒体类型 Accept-Charset 用于指定客户端接受的字符集 Accept-Encoding Date 请求发送的日期和时间 Cache相关 Etag/Last-Modified/(max-age/Expires) ContentType 文件类型 ContentType 7z application
Content-Length: 348 content-type补充 规范:只要Content-Type设置为application/json的时候,前台的data要传递String字符串 ajax设置了contentType
不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式. 代码如: <% response.ContentType =”text/html” %> <! –#i nclude virtual=”/ContentType.html” –> 显示的为网页,而 <% response.ContentType =”text/plain” %> <! –#i nclude virtual=”/sscript/ContentType.html” –> 则会显示html原代码. 以下为一些常用的 ContentType GIF images <% response.ContentType =”image/gif” %> <!
/x-www-form-urlencoded 如果想发送不想转换的的信息的时候需要手动将其设置为false 在遇到的是传输的是blob对象的时候就是不需要将传输的数据序列化,一般的还有类似DOM树等 contentType 发送信息至服务器时内容编码类型(告诉服务器从浏览器提交过来的数据格式),默认值为contentType = "application/x-www-form-urlencoded" 在 ajax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件。
在网上查到说是:“包含页面与被包含页面的@page指令里面的contentType不一致,仔细检查两个文件第一行的 @page.....” <%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %> <% String path
该ContentType的属性包含请求的媒体类型。分配给ContentType属性的值在请求发送Content-typeHTTP标头时替换任何现有内容。 要清除Content-typeHTTP标头,请将ContentType属性设置为null。 此属性的值存储在WebHeaderCollection中。 参考示例代码: 1 private HttpResult Request(string url, string data, string method, string contentType) 2 13 *所以放置在Headers 属性之后设置 14 */ 15 httpWebRequest.ContentType = contentType; 16 } 41 catch (Exception ex) 42 { 43 GetExceptionResponse(ref httpResult, ex, method, contentType
使用指定名称和值设置响应头的名称和内容 22 void setLocale(Locale loc) 设置响应的语言环境,如果响应尚未被提交的话 23 void setStatus(int sc) 设置响应的状态码 动态响应contentType 属性: 如果一个客户请求访问一个JSP页面时,如果该页面用page指令设置页面的contentType属性值为text/html,那么JSP引擎将按这种属性作出响应,将页面静态部分返回给客户。 由于page指令只能为contentType指定一个值,来决定响应的MIME类型,通过response.setContentType(String s);方法可以动态改变contentType的值,响应的 , String message) 此方法将一个状态码(通常为 404)和一个短消息,自动插入HTML文档中并发回给客户端 demod.jsp <%@ page language="java" contentType ="submit" value="excel" name="submit_e"> </form> </body> </html> tree3.jsp <%@ page language="java" contentType
org.apache.jasper.JasperException: /jsp.jsp(1,2) Page directive: illegal to have multiple occurrences of contentType ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown Source) 主文件: <%@ page language="java" contentType -- --> </body> </html> 插入文件: <%@ page language="java" contentType="text/html; carset=UTF-8" pageEncoding
1、文本格式:html、xml、txt Response.ContentType = “text/html “; Response.ContentType = “text/xml”; Response.ContentType = “text/plain”; 2、图片格式 Response.ContentType = “image/jpg”; Response.ContentType = “image/png”; Response.ContentType = “image/gif”; 3、媒体格式 Response.ContentType = “application/json”; //比较常用 Response.ContentType = “application /xml”; Response.ContentType = “application/xhtml+xml”; Response.ContentType = “application/atom+xml”; Response.ContentType = “application/pdf”; Response.ContentType = “application/msword”; Response.ContentType