java - 在 Tomcat 中检索文件时出现问题

标签 java servlets tomcat6

我正在从事网络应用程序工作。使用的服务器是 Apache Tomcat 6。运行服务器后,我尝试从 mylocalhost http://localhost:8080/examples/README.txt 访问资源。但我无法访问显示 Eclipse 中未找到错误消息文件的资源。但是,如果我按 ctrl+左键单击链接,资源就会在 Eclipse 工作区中打开。我无需通过服务器即可访问相同的资源,即转到路径 C:\Program Files (x86)\apache-tomcat-6.0.35\bin 并单击 Startup.bat。这样我就可以打开文件了。我可以知道无法通过 Eclipse 访问该资源的原因是什么吗?

url = new URL("http://localhost:8080/examples/README.txt");
con = url.openConnection(); // open the url connection.
dis = new DataInputStream(con.getInputStream()); 

最佳答案

这是我从前面提到的博客中引用的内容

Tomcat actually consists of 2 aspects: a sharable codebase (CATALINA_HOME) and a per-instance part (CATALINA_BASE). This allows multiple copies of Tomcat to run on a single server using one codebase. Most of the time, CATALINA_HOME and CATALINA_BASE are the same value, since more often than not, only one copy of a given version of Tomcat is is use – at least on a developer’s machine.

When you create a Tomcat server using the Eclipse Servers facility, however, it clandestinely creates its own CATALINA_BASE, copying selected files – and only those files into a directory owned by the plugin.

I got burned. I was keeping a file of my own in CATALINA_HOME and using a relative reference to it in server.xml. The file didn’t copy and Tomcat didn’t start clean.

The simplest solution was to edit server.xml and replace the relative path to an absolute path, so that the copied configuration would be able to locate the original (and in this case, the only) copy of my file.

Apparently, however, the copying of the CATALINA_BASE data occurs only when you create a new Server definition. I had to delete the old Server definition from Eclipse and create a new one to get the changes to take.

我从这篇文章中相信,Eclipse 服务器仅复制选定的文件,并且您的文件不会被复制。看看这篇文章,想想这对你的问题是否有意义。 本

关于java - 在 Tomcat 中检索文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12454864/

相关文章:

java - 从十六进制/二进制序列中获取每一位

java - 模拟特定类对象 stub 失败的测试mockito

jsp - JspServlet中的 "mappedfile"参数代表什么?

tomcat启动问题

java - 从 Http 响应读取数据很少引发 BindException : Address already in use

java - 收到致命警报 : handshake_failure with Tomcat

java - 如何打印出列表中的一个元素以及所有元素

java - PagerTabStrip 无法解析为类型

rest - RESTful Web 服务与仅使用简单的 Servlet 相比有什么好处?

java - 用Java处理html日期输入