设为首页 加入收藏

TOP

Linux下设置Tomcat虚拟路径(一)
2017-10-13 10:36:45 】 浏览:948
Tags:Linux 设置 Tomcat 虚拟 路径

问题描述我在上传图片的位置不在Tomcat服务器下,用户无法访问

解决方案:配置Tomcat虚拟路径使用户可以访问图片

 

配置Tomcat

# cd /usr/local/apache-tomcat-7.0.67/conf/  //切换到Tomcat下的配置文件

# vi server.xml   //编辑Tomcat 的server.xml文件

找到Host节点,在Host节点下加入如下代码:

 

<Context path="访问路径" docBase="文件夹路径" debug="debug的等级" reloadable="热加载状态"/>
//修改完成后,按ESC退出编辑模式
//按Shift+q 切到控制台模式
//输入wq保存修改信息

 例子:

  <Context path="/test" docBase="/usr/img" debug="0" reloadable="true" crosscontext="true" />

  debug="0"        : debug 取值为0时,提供最少的debug信息,取值为9时,提供最多的debug信息

  path=“/test”      : path为访问路径,http://localhost:8080/test/1.jpg

  docBase="/usr/img"   : docBase为项目路径,比如,我只想让这个路径能获取图片,那么就设置为图片所在的路径

  reloadable="true"       : reloadable=true时 当web.xml或者class有改动的时候都会自动重新加载不需要从新启动服务

  crosscontext="true"   :表示配置的不同context共享一个session

以上配置的项目路径或其他的虚拟路径,端口号是一样的    http://localhost:8080/test/1.jpg

下面是我的Tomcat server.xml文件的配置的截图 和代码

<?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 className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- 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
       Document
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Linux shell ftp命令下载文件 根.. 下一篇linux管理面板

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目