[英]Tomcat seems to ignore new <Context> element in server.xml
after reading various questions about how to handle images on tomcat I followed the approach to set a folder with images at tomcat following the instructions here: Simplest way to serve static data from outside the application server in a Java web application but it doesn't work and I cannot understand what I am doing wrong. 在阅读了有关如何在tomcat上处理图像的各种问题之后,我按照以下说明按照以下方法在tomcat上设置了带有图像的文件夹: 从Java Web应用程序中的应用程序服务器外部提供静态数据的最简单方法,但是它不起作用而且我不明白我在做什么错。
I've set the context in server.xml as described: 我已经按照描述在server.xml中设置了上下文:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context docBase="C:\ServerFiles\" path="/images" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
and I also tried this: 我也尝试过这个:
<Context docBase="C:\ServerFiles" path="/images" />
instead of the above. 而不是上面的。
The image is located at 图片位于
C:\\ServerFiles
and its name is index.jpg
C:\\ServerFiles
,名称为index.jpg
and this is how i try to retrieve it with jsf 这就是我尝试用jsf检索它的方式
<img src="/images/index.jpg" />
but it doens't work 但这不起作用
Can you help me? 你能帮助我吗? I cannot understand what I am doing wrong. 我不明白我在做什么错。
If editing Tomcat's server.xml
(or context.xml
or web.xml
or what not which resides in its /conf
folder) appears to have no effect, then it's a strong hint that you're using an IDE which has taken over the control from Tomcat. 如果编辑Tomcat的server.xml
(或context.xml
或web.xml
或/conf
文件夹中没有的内容)似乎无效,则强烈暗示您使用的是接管了控件的IDE来自Tomcat。 Eclipse for example does that by default. 例如,Eclipse默认情况下会这样做。 When you add Tomcat server in Eclipse, then it basically creates a copy of its /conf
folder into the IDE's Servers project, uses the IDE workspace as deploy space and solely uses Tomcat server's engine to run projects against the config in Servers project and deployments inside workspace. 在Eclipse中添加Tomcat服务器时,它基本上会在IDE的Servers项目中创建其/conf
文件夹的副本,使用IDE工作区作为部署空间,并且仅使用Tomcat服务器的引擎针对Servers项目中的config和内部部署运行项目工作区。
You have basically 2 options: 您基本上有2个选择:
Edit the configuration files in Servers project instead. 而是在“ 服务器”项目中编辑配置文件。
Tell Eclipse to not take over control from Tomcat but instead use (and manipulate!) it directly. 告诉Eclipse 不要接管Tomcat的控制权,而应直接使用(并操纵!)它。 Doubleclick the Tomcat entry in Servers view, select in the section Server location the option Use Tomcat installation . 在“ 服务器”视图中双击Tomcat条目,在“ 服务器位置 ”部分中选择“ 使用Tomcat安装 ”选项。
The way you've defined Context should work. 您定义上下文的方式应该起作用。 I cross checked a project where I do this and I didn't see any issue on your server.xml
. 我交叉检查了执行此操作的项目,但在server.xml
上未发现任何问题。
Maybe you have a separate context.xml
in the METAINF
folder of your web module that overrides the setting here. 也许您的Web模块的METAINF
文件夹中有一个单独的context.xml
,它会覆盖此处的设置。
BTW the second example without the trailing \\
is the correct way to do it. 顺便说一句,第二个示例没有尾随\\
是正确的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.