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

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

报告相同问题?