JSP contentType 属性

JSP 的page指令 的contentType属性用于在发送到客户端的响应头中设置文档的MIME 类型。 MIME代表多用途 Internet 邮件扩展。MIME 类型是一种告诉浏览器应该打开文件的特定格式的方法。
 

一些重要的 MIME 类型值:

MIME Type ValuesDescription
text/htmlHTML Document
text/plainPlain Text Document
text/xmlXML Document
text/cssCasacading Style Sheets
image/pngPNG Image
image/gifGIF Image
image/jpegJPEG Image
mpeg/videoMPEG Video Clip.
audio/midiMIDI Audio File.
application/pdfPDF File
application/wordMS-WORD File


 

将 contentType 设置为 MIME 类型值为“text/plain”


page指令的contentType属性设置为值“text/plain” 告诉浏览器将 JSP 网页作为纯文本文档打开。让我们看看它是如何完成的。 内容类型.jsp
 

<!–– Example of contentType attribute of page directive of JSP -->

<html>

<head>
	<title>The contentType Attribute</title>
</head>


<body>

Setting the contentType to text/plain
<br/>

<%@ page contentType = "text/plain" %>
<b>This is going to be displayed as a plain text only to the user.</b>

</body>

</html>


执行上述 JSP 网页会强制浏览器以纯文本格式显示该页面。

 

将 contentType 设置为 MIME 类型值为“text/xml”


page指令的contentType属性设置为值“text/xml”告诉浏览器将 JSP 网页的内容作为XML文档打开。让我们看看它是如何完成的。 ContentType2.jsp
 

<!–– Example of contentType attribute of page directive of JSP -->

<html>

<head>
<title>The contentType Attribute</title>
</head>


<body>

Setting contentType to text/xml.
<br/>

<%@ page contentType = "text/xml" %>
<b>The text on this page going to be displayed only in the form of text/xml to the user.</b>

</body>

</html>


执行上述 JSP 网页会导致浏览器以XML格式显示该页面。


 

使用“text/html”的 MIME 类型值设置 contentType


page指令的contentType属性设置为值“text/html”告诉浏览器将此 JSP 网页作为 HTML 文档打开。让我们看看它是如何完成的。 ContentType3.jsp
 

<!–– Example of contentType attribute of page directive of JSP -->

<html>

<head>
<title>The contentType Attribute</title>
</head>


<body>

Setting the contentType to text/plain
<br/>

<%@ page contentType = "text/html" %>
<b>The text on this page is displayed only in the form of html to user.</b>

</body>

</html>


执行上述 JSP 网页会导致浏览器以其默认的 HTML 文档格式显示该页面。
 

 

笔记 -


默认的 MIME 类型是“text/html”。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值