jsp中打开pdf文件:中文目录(中文文件名)问题:还望大虾们帮助,不胜感激

lymkelly 2003-09-19 04:25:31
jsp中打开pdf文件:中文目录(中文文件名)问题
我的
直接打开
或者
用输入输出流

英文的目录,文件名实现了

但是,中文的目录名,文件名实现不了
上面的实现在另外一个贴字里http://expert.csdn.net/Expert/topic/2271/2271350.xml?temp=.7396814

还望大虾帮助,不胜感激
...全文
500 40 打赏 收藏 转发到动态 举报
写回复
用AI写文章
40 条回复
切换为时间正序
请发表友善的回复…
发表回复
kettycat 2003-09-25
  • 打赏
  • 举报
回复
up
lymkelly 2003-09-24
  • 打赏
  • 举报
回复
liad() ( ) 大虾

words时不时
也可以用这种方式打开呢
现在我的问题是

一个目录下面好多文档
不同的扩展名
不知道怎样才能统一起来
lymkelly 2003-09-24
  • 打赏
  • 举报
回复
to:intelchen(intelchen)
我给你发了
lymkelly 2003-09-24
  • 打赏
  • 举报
回复
logs\目录下面没有stderr.log
stdout.log这两个文件,
只有类似

localhost_admin_log.2003-09-23.txt
的文件

liad() 大虾说的那个用*的,有没有解决中文问题呢

我原来对流这一块一窍不通,现在有了开始,
好好研究一下
lymkelly 2003-09-24
  • 打赏
  • 举报
回复
liad() (大虾
基本上解决了问题
但是呢 如国我的文件名
中有空格,
就会有问题
找不到
lymkelly 2003-09-24
  • 打赏
  • 举报
回复
liad() (大虾
我崇拜的不行了
哎呀
真是太厉害了!!!!!!!!!


lymkelly 2003-09-24
  • 打赏
  • 举报
回复
liad() (大虾
又有了新的进展了阿!!
太好了
我去试一试
liad 2003-09-24
  • 打赏
  • 举报
回复
utf8encode.jsp
==============
<%@ page contentType="text/html; charset=UTF8" pageEncoding="gb2312" %>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<p>
<%= java.net.URLEncoder.encode("测试", "UTF8") %>
<p>
<%= java.net.URLEncoder.encode("文档", "UTF8") %>
</BODY>
</HTML>

html页面输出
%E6%B5%8B%E8%AF%95

%E6%96%87%E6%A1%A3

然后用http://localhost:8080/test/%E6%B5%8B%E8%AF%95/%E6%96%87%E6%A1%A3.pdf
就可直接访问E:\Tomcat4.1\webapps\test\测试\文档.pdf,而不需要什么servlet来处理

由于使用了
<%@ page contentType="text/html; charset=UTF8" pageEncoding="gb2312" %>
所以在google输入关键字“测试”并提交,URL变成了
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=%E6%B5%8B%E8%AF%95&btnG=Google+Search

而在baidu里面没有将charset设为UTF8
所以在其上面提交关键字“测试”后,URL为
http://www1.baidu.com/baidu?cl=3&tn=baidu&f=4&ct=0&lm=0&word=%B2%E2%CA%D4
liad 2003-09-23
  • 打赏
  • 举报
回复
如果你的tomcat已经转化为windows服务时,你可以通过
E:\Tomcat4.1\logs\stderr.log
E:\Tomcat4.1\logs\stdout.log
看到出错信息和控制台输出信息
lymkelly 2003-09-23
  • 打赏
  • 举报
回复
感谢liad() (
成功了
用你说的 绝对路经的那一个
!!!!!!!!
非常感谢!!!!!!!!


我明天在看一看就揭帖,谢谢

终于冲破了黑暗了!1
完成以后要好好的 研究一下这个地方
非常感谢
intelchen 2003-09-23
  • 打赏
  • 举报
回复
楼主我对那个BPM_Tutorial.pdf敢兴趣

能不能把这个文件发到intelchen@163.net?

你们做BMP的东西吗?
lymkelly 2003-09-23
  • 打赏
  • 举报
回复
to
:liad() (
我觉得如果你的验证成功化的
我的就是目录有了问题
你要执行这个servlet 的话,
按照你的那个部署web.xml的部署

我可能就是中文的目录方错了地方了
我试用一下
用你刚才的
那个绝对路径的
in


liad 2003-09-23
  • 打赏
  • 举报
回复
还有一种方法就是使用
web.xml
=======
<servlet-mapping>
<servlet-name>PdfServlet</servlet-name>
<url-pattern>*.pdf</url-pattern>
</servlet-mapping>
pdf文件都使用PdfServlet去处理,不过DispPDF.java有所改变
这样直接在http://localhost:8080/test/abc.pdf,但是这种方法我没有试验成功中文路径的,request.getServletPath()还搞不定,正在调试
lymkelly 2003-09-23
  • 打赏
  • 举报
回复
哎呀!@

错了
这样





我用的一个大虾的办法:
中文的不可以
英文的可以
大家看一下
java.io.FileNotFoundException: http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/张立国/BPM_Tutorial.pdf

import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testPDF extends HttpServlet{
public void init(ServletConfig servletconfig)
throws ServletException
{
super.init(servletconfig);


}

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out =res.getOutputStream ();
res.setContentType( "application/pdf" ); // MIME type for pdf doc
res.setHeader("Content-disposition","attachment; filename=" +"BPM_Tutorial.pdf" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL("http","127.0.0.1",8080,"/kyglxxxt/PROJECT/BPM_Tutorial.pdf");
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}

这样就显示正常,不过要谈出两个保存框(要是在jsp中直接使用超级连接,英文的直接就可以显示,没有保存况,所以说。。。。。。。这个方法也是没有用,写出来和那个中文的作个对比)
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testPDF extends HttpServlet{
public void init(ServletConfig servletconfig)
throws ServletException
{
super.init(servletconfig);


}

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out =res.getOutputStream ();
res.setContentType( "application/pdf" ); // MIME type for pdf doc
String fileURL ="http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/张立国/BPM_Tutorial.pdf";
res.setHeader("Content-disposition","attachment; filename=" +"BPM_Tutorial.pdf" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url =new URL(fileURL);

bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}

这样还是不行,错误是:java.io.FileNotFoundException: http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/张立国/BPM_Tutorial.pdf"



liad 2003-09-23
  • 打赏
  • 举报
回复
in = new BufferedInputStream(new FileInputStream("E:/Tomcat4.1/webapps/test/测试/文档.pdf"));
web.xml
=======
<servlet>
<servlet-name>PdfServlet</servlet-name>
<display-name>Pdf Servlet</display-name>
<servlet-class>pdf.DispPDF</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>PdfServlet</servlet-name>
<url-pattern>/servlet/PdfServlet</url-pattern>
</servlet-mapping>

然后用http://localhost:8080/test/servlet/PdfServlet

我的完全可以,要不我也不会贴出代码
lymkelly 2003-09-23
  • 打赏
  • 举报
回复
英文的也不行!!!
总是空白的也面!!!!!!!1






我用的一个大虾的办法:
中文的不可以
英文的可以
大家看一下
java.io.FileNotFoundException: http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/张立国/BPM_Tutorial.pdf

import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testPDF extends HttpServlet{
public void init(ServletConfig servletconfig)
throws ServletException
{
super.init(servletconfig);


}

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out =res.getOutputStream ();
res.setContentType( "application/pdf" ); // MIME type for pdf doc
res.setHeader("Content-disposition","attachment; filename=" +"BPM_Tutorial.pdf" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url = new URL("http","127.0.0.1",8080,"/kyglxxxt/PROJECT/BPM_Tutorial.pdf");
bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}

这样就显示正常,不过要谈出两个保存框(要是在jsp中直接使用超级连接,英文的直接就可以显示,没有保存况,所以说。。。。。。。这个方法也是没有用,写出来和那个中文的作个对比)
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class testPDF extends HttpServlet{
public void init(ServletConfig servletconfig)
throws ServletException
{
super.init(servletconfig);


}

public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out =res.getOutputStream ();
res.setContentType( "application/pdf" ); // MIME type for pdf doc
String fileURL ="http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/魏振钢/BPM_Tutorial.pdf";
res.setHeader("Content-disposition","attachment; filename=" +"BPM_Tutorial.pdf" );
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
URL url =new URL(fileURL);

bis = new BufferedInputStream(url.openStream());
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff, 0, bytesRead);
}
} catch(final MalformedURLException e) {
System.out.println ( "MalformedURLException." );
throw e;
} catch(final IOException e) {
System.out.println ( "IOException." );
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
}
}

这样还是不行,错误是:java.io.FileNotFoundException: http://127.0.0.1:8080/kyglxxxt/PROJECT/开发/2003/张立国/BPM_Tutorial.pdf"



lymkelly 2003-09-23
  • 打赏
  • 举报
回复
to:liad() (:
我试验了 不行的
中文的不行
英文的可以
csdnxw 2003-09-23
  • 打赏
  • 举报
回复
这位老兄跟张兄认识?
lymkelly 2003-09-23
  • 打赏
  • 举报
回复
楼上的理解对吗???????????
大虾指教
intelchen 2003-09-23
  • 打赏
  • 举报
回复
个人觉得kinoviti(-=K.V=-) 那个是正解,
但是我不确定最后一句话“同时再每一位转换成的16进制头尾分别
加上%”
如果我的路径是“http://localhost/english/雅 思/雅思英语学习/东方雅思资料.pdf”
对应到我的文件系统的路径是"c:/tomcat/webapps/english/雅 思/雅思英语学习/东方雅思资料.pdf"
我是不是只要将“c:/tomcat/webapps/english/”保持不变“/雅 思/雅思英语学习/东方雅思资料.pdf”的每个字符(包括空格之类的特殊符号)前加上%就可以?
如果是路径是“c:/tomcat/webapps/english/雅 思/雅思英语学习/pdf/东方雅思资料.pdf”
那“雅 思/雅思英语学习/pdf/东方雅思资料.pdf”中的那个“pdf”并不需要加上%?
不知道你有没有源程序给我们看看?

加载更多回复(20)

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧