焦急在线等待:url地址中的中文问题?请高手出手! ( 积分: 200 )

  • 主题发起人 wxb761014
  • 开始时间
W

wxb761014

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢各位回答,不过这些办法我试了都不行。
偶尔在csdn上发现一个办法,试试也还可以,虽然不是很完美。
这是简单的JSP,你可以改造成SERVLET,使用方法,例如此文件名是getfile.jsp
与此文件的同目录下有一个test.doc的word目录,则用
http://localhost/getfile.jsp?file=test.doc
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
String filename = "";
if (request.getParameter("file") != null) {
filename = request.getParameter("file");
}
response.setContentType("application/msword");
response.setHeader("Content-disposition","attachment;
filename="+filename);

BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("" + filename)));
bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
}
} catch(final IOException e) {
System.out.println ( "³öÏÖIOException." + e );
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
//return;
%>
这里,我真得感谢这个作者。
链接是:http://search.csdn.net/Expert/topic/1693/1693378.xml?temp=.373974
看来还是csdn上java高手多啊。
 
W

wxb761014

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
Z

ZYONG

Unregistered / Unconfirmed
GUEST, unregistred user!
嗐,头痛医脚!
 
顶部