日期:2014-05-18  浏览次数:20627 次

[JSP][tomcat][linux] 引用工程外的文件的路径问题
eclipse3.2   +   lomboz   +   tomcat5.5   +   JDK1.5,   fedora   core   6,   windows   xp

给desktop   search(基于lucene)作前端,要在一JSP页面上建立到本地硬盘的HTML文件的超链接,形如(为描述方便hardcode)

//   for   winxp
String   filePath   =   new   String( "c:\\root\\test.html ");

//   for   linux
String   filePath   =   new   String( "/root/test.html ");

<A   href= " <%=   filePath   %> "> testlink </A>


启动汤姆猫
在winxp下,查看   testlink   链接的属性为   file:///c:/root/test.html   点击链接就打开该文件,符合预期,很好很好。。
在linux下,查看   testlink   链接的属性为   http://localhost:8080/root/test.html   这应该是把   "/root/test.html "   当作相对web服务器的路径,链接指向   tomcat/webapps   目录下,点击链接自然   404   not   found


经同学指点,简便的解决办法是把   /root   作   ln   到   tomcat/webapps   里,这个办法虽然有效,但是没弹性、不elegant……并且实际上   filePath   是由   lucene   检索得来,换句话说   filePath   一定表示   本地文件系统   某文件的路径,该路径和   tomcat/webapps   的   相对路径关系   却是未知的   ——   需要把整个   "/ "   都   ln   到tomcat/webapps   里才能保证这种办法总是有效。这不安全、太ugly了,尽管桌面搜索只在本地运行,但还要考虑非   root   用户。


继而怀疑链接的写法问题,代码改为

String   filePath   =   new   String( "file:///root/test.html ")
<A   href= " <%=   filePath   %> "> testlink </A>

这次右键查看   testlink   的属性倒是正确了,指向   file:///root/test.html   ,但是!怎么点击链接TMD都没反应,不跳转……这这这,委实是件很憋屈的事情……

于是只能冰天雪地赤身裸体空中转身720度跪blz求各位指点,谢谢谢谢谢谢!!

------解决方案--------------------
不用那么惨吧 帮顶一下
------解决方案--------------------
LS
4条裤衩还到处帮顶....