怎样在jsp页面上读取服务器磁盘上的文件

一、配置虚拟路径

如:磁盘上保存的路径为E:/file

       虚拟路径配置为/upload

在tomcat的server.xml中配置:

<Host name="localhost"  appBase="webapps"  unpackWARs="true" autoDeploy="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"
               prefix="localhost_access_log." suffix=".txt"

               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

        <!-- 在配置文件中加入的内容 --!>

<Context docBase="E:/file/" path="/upload/" reloadable="true"/>

</Host>

二、在jsp页面上:

<img src="http://ip:端口号/upload/example.jpg"/>

猜你喜欢

转载自blog.csdn.net/lzg319/article/details/80390639