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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog