看点:response对象,setContentType(String type)方法的使用示例。

说明:setContentType(String type)方法,指的是响应设置内容类型头。参数type可取text/html,text/plain,application/x-msexcel,application/msword等值。

 

示例目的:动态设置contentType属性,以不同方式打开文件list.txt。

 

choice.jsp

<html>

<head>

<title>以提供的不同方式打开文件示例</title>

</head>

<body>

<font size=4>

<p>请选择打开文本文件list.txt的方式!

<p><jsp:include page="list.txt"/> //使用动态标签<jsp:include>添加静态文件。

<form action="contentType.jsp" method="post" name=form>

<input type="submit" value="word" name="word">

<input type="submit" value="excel" name="excel">

</form>

</font>

</body>

</html>

 

contentType.jsp

"<%@page contentType="text/html;charset=gb2312" %>"

<html>

<head>

<title>以不同方式打开文件示例</title>

</head>

<body>

<%

String str1=request.getParameter("word");

String str2=request.getParameter("excel");

if(str1==null)

{

str1="";

}

if(str2==null)

{

str2="";

}

if(str1.equals("word"))

{//设置Word类型。

response.setContentType("application/msword;charset=gb2312");

}

if(str2.equals("excel"))

{//设置excel类型。

response.setContentType("application/x-msexcel;charset=gb2312");

}

%>

<jsp;include page="list.txt"/>

</body>

</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值