IDEA项目中前端不能获取前端分类图片

IDEA项目中前端不能获取前端分类图片

<?xml version="1.0" encoding="UTF-8"?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  this work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0

  (the "License"); you may not use this file except in compliance with

  the License.  You may obtain a copy of the License at


      http://www.apache.org/licenses/LICENSE-2.0


  Unless required by applicable law or agreed to in writing, software

  distributed under the License is distributed on an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

--><!-- Note:  A "Server" is not itself a "Container", so you may not

     define subcomponents such as "Valves" at this level.

     Documentation at /docs/config/server.html

 --><Server port="8005" shutdown="SHUTDOWN">

  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>

  <!-- Security listener. Documentation at /docs/config/listeners.html

  <Listener className="org.apache.catalina.security.SecurityListener" />

  -->

  <!--APR library loader. Documentation at /docs/apr.html -->

  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>

  <!-- Prevent memory leaks due to use of particular java/javax APIs-->

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>


  <!-- Global JNDI resources

       Documentation at /docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>

  </GlobalNamingResources>


  <!-- A "Service" is a collection of one or more "Connectors" that share

       a single "Container" Note:  A "Service" is not itself a "Container",

       so you may not define subcomponents such as "Valves" at this level.

       Documentation at /docs/config/service.html

   -->

  <Service name="Catalina">


    <!--The connectors can use a shared executor, you can define one or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->



    <!-- A "Connector" represents an endpoint by which requests are received

         and responses are returned. Documentation at :

         Java HTTP Connector: /docs/config/http.html

         Java AJP  Connector: /docs/config/ajp.html

         APR (HTTP/AJP) Connector: /docs/apr.html

         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080

    -->

    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

    <!-- A "Connector" using the shared thread pool-->

    <!--

    <Connector executor="tomcatThreadPool"

               port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    -->

    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443

         This connector uses the NIO implementation. The default

         SSLImplementation will depend on the presence of the APR/native

         library and the useOpenSSL attribute of the

         AprLifecycleListener.

         Either JSSE or OpenSSL style configuration may be used regardless of

         the SSLImplementation selected. JSSE style configuration is used below.

    -->

    <!--

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"

               maxThreads="150" SSLEnabled="true">

        <SSLHostConfig>

            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"

                         type="RSA" />

        </SSLHostConfig>

    </Connector>

    -->

    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2

         This connector uses the APR/native implementation which always uses

         OpenSSL for TLS.

         Either JSSE or OpenSSL style configuration may be used. OpenSSL style

         configuration is used below.

    -->

    <!--

    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"

               maxThreads="150" SSLEnabled="true" >

        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />

        <SSLHostConfig>

            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"

                         certificateFile="conf/localhost-rsa-cert.pem"

                         certificateChainFile="conf/localhost-rsa-chain.pem"

                         type="RSA" />

        </SSLHostConfig>

    </Connector>

    -->


    <!-- Define an AJP 1.3 Connector on port 8009 -->

    <!--

    <Connector protocol="AJP/1.3"

               address="::1"

               port="8009"

               redirectPort="8443" />

    -->


    <!-- An Engine represents the entry point (within Catalina) that processes

         every request.  The Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to the appropriate Host (virtual host).

         Documentation at /docs/config/engine.html -->


    <!-- You should set jvmRoute to support load-balancing via AJP ie :

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

    -->

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


      <!--For clustering, please take a look at documentation at:

          /docs/cluster-howto.html  (simple how to)

          /docs/config/cluster.html (reference documentation) -->

      <!--

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

      -->


      <!-- Use the LockOutRealm to prevent attempts to guess user passwords

           via a brute-force attack -->

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

        <!-- This Realm uses the UserDatabase configured in the global JNDI

             resources under the key "UserDatabase".  Any edits

             that are performed against this UserDatabase are immediately

             available for use by the Realm.  -->

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

      </Realm>


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


        <!-- SingleSignOn valve, share authentication between web applications

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

        <!--

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

        -->


        <!-- Access log processes all example.

             Documentation at: /docs/config/valve.html

             Note: The pattern used is equivalent to using pattern="common" -->

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>


      <Context docBase="D:\apache-tomcat-8.5.55\webapps\message" path="/message" reloadable="true" source="org.eclipse.jst.jee.server:message"/>

        <Context docBase="D:\webimages\projectdev\image\upload" path="/upload" />

      </Host>

    </Engine>

  </Service>

</Server>

使用IDEA做的项目,前台不能获取图片

https://img1.sycdn.imooc.com//climg/614f3a8d09df12e111690645.jpg

https://img1.sycdn.imooc.com//climg/614f3a8e09926e7e12220720.jpg

本机路径如下

https://img1.sycdn.imooc.com//climg/614f3a8e096f7ebc11570472.jpg

数据库中的路径

https://img1.sycdn.imooc.com//climg/614f3a8e0960a38612880566.jpg


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕小脸 2021-09-28 10:44:25

同学你好,经反复检查,发现同学本地的图片是放在如下位置处的:

https://img1.sycdn.imooc.com//climg/6152807009469a5205970045.jpg

而在数据库显示的路径中多了images文件夹,从而导致图片找不到

https://img1.sycdn.imooc.com//climg/615280a009d7073a09940300.jpg

这里需要同学在D盘的upload文件夹下再创建一个images文件夹,然后将item之后的文件夹放置进去,也就是如下这样:

https://img1.sycdn.imooc.com//climg/6152810209a9c97f07590125.jpg

祝学习愉快~

  • 提问者 视线模糊 #1

    D:\webimages\projectdev\image\upload\images\item,按老师说的新建立了images文件后,确实能获得图片了,具体路径如下,但是Tomcat中的代码没有修改,也能获得图片,这个解析没有理解   <Context docBase="D:\webimages\projectdev\image\upload" path="/upload" />,是不是这个解析写到上一级目录也可以正确读取?


    https://img1.sycdn.imooc.com//climg/6162bf8b091ddffc09560274.jpg

    2021-10-10 18:51:19
  • 好帮手慕小脸 回复 提问者 视线模糊 #2

    同学你好,这里path设置为/upload后,url路径如果包含upload那么就会自动解析这个路径(D:\webimages\projectdev\image\upload),而这个路径正好能对应上如下这部分:

    https://img1.sycdn.imooc.com//climg/61639d680980567206660056.jpg

    所以后面添加images不影响程序的运行~

    注:在本小节的课程中老师有讲解,同学可以重新看课~

    祝学习愉快~

    2021-10-11 10:32:29
好帮手慕小脸 2021-09-26 11:52:43

同学你好,建议同学使用鼠标悬停在图片路径上,看一下它实际拼出的路径是什么。是否和预期一致呢?

https://img1.sycdn.imooc.com//climg/614fe67a094026d305530080.jpg

若idea配置上下文路径中有设置项目名,那么同学是否添加项目名呢?

祝学习愉快~

  • 提问者 视线模糊 #1

    文件实际放置的位置D:\webimages\projectdev\image\upload\item\shopcategory,前端显示的位置如下

    https://img1.sycdn.imooc.com//climg/61507be90929dfe213330652.jpg



    ,但是Tomcat的server.xml我设置了<Context docBase="D:\webimages\projectdev\image\upload" path="/upload" />,不知道为什么没有获取到图片?

    2021-09-26 21:56:17
  • 好帮手慕小脸 回复 提问者 视线模糊 #2

    同学你好,从同学的截图中看,图片路径前缺少o2o项目名,如:

    https://img1.sycdn.imooc.com//climg/6151328b09dbc76d05490097.jpg

    这里建议同学在前边加上项目名o2o,直接访问试试,如:

    localhost:8080/o2o/upload\images\item\shopcategory\xx.png

    祝学习愉快~

    2021-09-27 10:56:46
  • 提问者 视线模糊 回复 好帮手慕小脸 #3

    不行,加项目名称不可以访问到图片,实际存储的图片路径为D:\webimages\projectdev\image\upload\item\shopcategory

    Tomcat中的配置是按视频中做的啊,不知道怎么回事就是访问不了图片

    https://img1.sycdn.imooc.com//climg/6151cc0f09019bd009610311.jpg

    https://img1.sycdn.imooc.com//climg/6151cc10092c86a308750418.jpg


    2021-09-27 21:51:49
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师