1.为什么setcontenttype文件的后缀名仍然是.jsp,比如我设置response.setContentType("text/application/msword")下载后的文件仍然是.jsp不应该是·doc吗?(还有这个帖子怎么把我的代码执行了,下面的学生成绩表不应该是代码吗?
2.代码如下
```<%@ page language="java" contentType="text/html;charset=gbk"
pageEncoding="utf-8"%>
学号 | 姓名 | 成绩 |
---|---|---|
124 | 蓝天 | 1 |
125 | 白云 | 2 |
126 | 田园 | 3 |
127 | 荒野 | 4 |
<%//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>