在Tomcat服务器上加载静态文件

时间:2017-05-15 14:59:27

标签: java tomcat directory

我遇到其他人在Tomcat服务器上加载静态文件(例如html)时遇到的问题。在guide on accessing local files from a tomcat server之后,我已将<Context docBase="F:/Sprint000" path="/static" />添加到server.xml文件中。我一直收到404错误。我假设根文件夹是`webapps&#39;?

有什么想法吗?

指南:webapps/Sprint000/index.htm

的Server.xml

<Engine name="Catalina" defaultHost="localhost">

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      <Realm className="org.apache.catalina.realm.LockOutRealm">

        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

             Documentation at: /docs/config/valve.html -->

        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

       <Context docBase="/Sprint000" path="/static" />  
        <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>
    </Engine> 

1 个答案:

答案 0 :(得分:0)

查找文件context.xml,将其编辑为:

<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true">
    <Resources>
        <PreResources
            base="F://Sprint000"
            className="org.apache.catalina.webresources.DirResourceSet"
            webAppMount="/static" />
    </Resources>
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
        allow=".*" />
</Context>