简体   繁体   English

Tomcat似乎无视新 <Context> server.xml中的元素

[英]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 &quot;%r&quot; %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.xmlweb.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个选择:

  1. Edit the configuration files in Servers project instead. 而是在“ 服务器”项目中编辑配置文件。

  2. 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.

相关问题 server.xml中定义的tomcat上下文未加载 - tomcat context defined in server.xml is not loading 在openshift中的tomcat server.xml中定义上下文 - Define a context in tomcat server.xml in openshift Tomcat通过server.xml映射上下文 - Tomcat mapping context via server.xml 为什么Intellij-IDEA会忽略我的tomcat / conf / server.xml Context标签? - Why does Intellij-IDEA ignore my tomcat/conf/server.xml Context tag? “Context”元素中的“source”属性在 Tomcat 的 server.xml 配置中代表什么? - What does the "source" attribute in a "Context" element represent in a Tomcat's server.xml configuration? 如何禁用通过Tomcat中server.xml的Context元素定义的应用程序? - How to disable application defined via Context element of server.xml in Tomcat? Openshift Tomcat,无法找到server.xml和context.xml? - Openshift tomcat, unable to find server.xml and context.xml? Jenkins Tomcat deploy:上下文是在server.xml中定义的,不能取消部署 - Jenkins Tomcat deploy : Context is defined in server.xml and may not be undeployed 使用Java从Tomcat的server.xml查找上下文路径 - Find context path from Tomcat's server.xml with java 如果没有部署应用程序 <context> 在tomcat的server.xml之外定义 - app is not deploying if <context> defined outside of server.xml in tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM