重新写下jsp页面:
<%@ page contentType="application/msword; charset=gb2312" language="java" errorPage="" %>
<html><head>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=temp.doc");
byte[] word=(byte[])request.getAttribute("scanlist");
javax.servlet.ServletOutputStream os = response.getOutputStream();
os.write(word);
os.close();
%>
</body>
</html>
<%@ page contentType="application/msword; charset=gb2312" language="java" errorPage="" %>
<html><head>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=temp.doc");
byte[] word=(byte[])request.getAttribute("scanlist");
javax.servlet.ServletOutputStream os = response.getOutputStream();
os.write(word);
os.close();
%>
</body>
</html>
<html><head>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
response.setContentType("application/msword");
//response.setHeader("Content-disposition","inline; filename=temp.doc");
String s= "MIJ";
byte[] word=s.getBytes();
javax.servlet.ServletOutputStream os = response.getOutputStream();
os.write(word);
os.close();
%>
</body>
</html>
<html>
<head>
<title>无标题文档</title>
</head>
<body>
<%
response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=temp.doc");
String s= "MIJ";
byte[] word=s.getBytes();
javax.servlet.ServletOutputStream os = response.getOutputStream();
os.write(word);
os.close();
%>
</body>
</html>
其实是这样的,我只要在页面里一调用
javax.servlet.ServletOutputStream os = response.getOutputStream();
就会出错。我也试过这样的写法:
<%@ page contentType="application/msword; charset=gb2312" language="java" errorPage="" %>
<html><head>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=temp.doc");
javax.servlet.ServletOutputStream os = response.getOutputStream();
%>
</body>
</html>
也是报相同的错,望ocean617(海洋)解答。谢谢。
import javax.servlet.*;
import javax.servlet.htt.*;
public class extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException ,ServletException
{
response.setContentType("application/ms-word;charset=gb2312");
PrintWriter out=response.getWriter();
out.print("ladj dlf asd f df ");
}
}
second last add
<%@ page contentType="application/msword;charset=gb2312"%>
这样也可以
........速度快了点‘
因该是import javax.servlet.http.*;
输出word应该用流吧,response.getWriter()是输出文本.