weixin_40583091 2019-04-18 21:05 采纳率: 100%
浏览 944
已结题

关于jsp中response.setContentType的问题

1.为什么setcontenttype文件的后缀名仍然是.jsp,比如我设置response.setContentType("text/application/msword")下载后的文件仍然是.jsp不应该是·doc吗?(还有这个帖子怎么把我的代码执行了,下面的学生成绩表不应该是代码吗?
2.代码如下图片说明图片说明图片说明图片说明

```<%@ page language="java" contentType="text/html;charset=gbk"
pageEncoding="utf-8"%>


Insert title here

学生成绩表
学号 姓名 成绩
124 蓝天 1
125 白云 2
126 田园 3
127 荒野 4
.html .txt .xls .doc

<%//request.setCharacterEncoding("gbk");
String ctype=request.getParameter("ctype") ;

if(ctype==null){}else if(ctype.equals("text/html")){
response.setContentType(ctype);
}else if(ctype.equals("text/plain")){
response.setContentType(ctype);
}else if(ctype.equals("application/x-msexcel")){
response.setContentType(ctype);
}else if(ctype.equals("application/msword")){
response.setContentType("application/msword;");
}%>

<%@ page language="java" contentType="text/html;charset=gbk"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>

<title>Insert title here</title>
</head>
<body>
<table border="3">
<caption>学生成绩表</caption>
<tr><th>学号</th><th>姓名</th><th>成绩</th></tr>
<tr><td>124</td><td>蓝天</td><td>1</td></tr>
<tr><td>125</td><td>白云</td><td>2</td></tr>
<tr><td>126</td><td>田园</td><td>3</td></tr>
<tr><td>127</td><td>荒野</td><td>4</td></tr></table>
<form action="" method="post">
<input type="radio" name="ctype" value="text/html">.html
<input type="radio" name="ctype" value="text/plain">.txt
<input type="radio" name="ctype" value="application/x-msexcel">.xls
<input type="radio" name="ctype" value="application/msword">.doc
<input type="submit">
</form>

<%//request.setCharacterEncoding("gbk");
String ctype=request.getParameter("ctype") ;

 if(ctype==null){}else if(ctype.equals("text/html")){
     response.setContentType(ctype);
     }else if(ctype.equals("text/plain")){
               response.setContentType(ctype);
               }else if(ctype.equals("application/x-msexcel")){
               response.setContentType(ctype);
               }else if(ctype.equals("application/msword")){
               response.setContentType("application/msword;");
           }%> 
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-04-18 22:13
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况