(一)Tomcat设置

2008-01-25 – 14:40 - 228 views

前言:前段时间学习了JAVA,主要是Stardard Edition部分,由于是自学看的不是太仔细只是了解了个大概,趁现在放假在家空余时间比较多所以想继续学下去,但是JAVA的知识体系实在是太庞大,所以只能一步一步来,所以这个寒假的主要任务就是学习下JSP,顺带巩固JAVA基础部分。由于自己看书实在是太枯燥了,所以我就在电驴上找了JSP的视频教程跟着学然后再照着练练巩固下,每天看两集,第二天写下学习笔记,这样希望能把前一天学的记住。

言归正传......(我装的是Tomcat 6.0.14版本)

Tomacat是一个WEB容器,所有的J2EE WEB程序可以在此处运行。常见的WEB容器还有WebLogic、WebSphere。

Tomcat的默认端口号是8080,这个数值可以在安装过程中修改也可以在conf/server.xml中修改。

Tomcat是根据系统的%JAVA_HOME%变量值选择系统中的JDK。

Tomcat目录主要文件夹作用

  • bin目录:存放启动和关闭Tomcat的脚本
  • conf目录:存放不同配置文件,其中比较重要的是server.xml(Tomcat的主要配置文件)和web.xml
  • work目录:存放JSP编译后的.class文件
  • webapps目录:存放WEB应用程序
  • lib目录:存放所有需要的各种jar包

配置Tomcat方式有两种:手工配置--修改conf/server.xml文件、管理控制台配置

  • 注意:修改server.xml之后要重新启动Tomcat服务器才能使配置生效

配置虚拟目录的要求

  • 修改server.xml文件
  • 虚拟目录的结构要符合要求
    • WebRoot
      • WEB-INF
        • web.xml
    • 其中web.xml的内容一般为:
      1. <?xml version="1.0" encoding="ISO-8859-1"?>
      2. <!--
      3. Licensed to the Apache Software Foundation (ASF) under one or more
      4.    contributor license agreements.   See the NOTICE file distributed with
      5.    this work for additional information regarding copyright ownership.
      6.    The ASF licenses this file to You under the Apache License, Version 2.0
      7.    (the "License"); you may not use this file except in compliance with
      8.    the License.   You may obtain a copy of the License at
      9.  
      10.       http://www.apache.org/licenses/LICENSE-2.0
      11.  
      12.    Unless required by applicable law or agreed to in writing, software
      13.    distributed under the License is distributed on an "AS IS" BASIS,
      14.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15.    See the License for the specific language governing permissions and
      16.    limitations under the License.
      17. -->
      18.  
      19. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      20.      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      21.      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      22.      version="2.4">
      23.  
      24.    <display-name>Welcome to Tomcat</display-name>
      25.    <description>
      26.       Welcome to Tomcat
      27.    </description>
      28.  
      29. <!-- JSPC servlet mappings start -->
      30.  
      31.  
      32. <!-- JSPC servlet mappings end -->
      33.  
      34. </web-app>

  • 创建好虚拟目录之后要在server.xml中</Host>之前添加一句<Context path="/映射名" docBase="/本机绝对地址" /> (大小写敏感,修改完之后应该重新启动Tomcat服务器使配置生效)

若设置虚拟目录后访问目录提示404错误而可以运行目录下的jsp文件则说明是目录权限被禁用,可以修改conf/web.xml文件找到<param-name>listings</param-name>将下面一行中的false改成true

jsp文件的运行过程: *.jsp  -->  *.java  -->  *.class  -->  运行显示 

  • *.class是第一次运行生成后存放在work目录下的,所以jsp文件第一次或者修改后首次运行比较慢而后来再运行的速度很快

您喜欢本文吗?即刻订阅"Alex's Blog",精彩文章不再错过!点击下列按钮收藏本文.

 

« 折腾 (二)JSP基本语法A »

发表回复