1、下载必要软件
①jdk 1.4.2
②tomcat 4.0
2、配置环境
windows系统用户:
我的电脑------〉右键-------〉属性-------〉详细-------〉环境变数
path = x:/jdk1.4.2/bin
java_home=x:/jdk1.4.2
catalina_home=x:/tomcat(这里有的是tomcat_home=x:/tomcat)
注:这里x为安装的驱动器。
这里要怎么设置取决于bin目录下的startup.bat文件。
我们可以在编辑状态下打开startup.bat,看究竟这个文件需要读取那个系统变量,我们就设置那个。比如当前我的版本tomcat的startup.bat文件内容如下:
@echo off
if "%os%" == "windows_nt" setlocal
rem ---------------------------------------------------------------------------
rem start script for the catalina server
rem
rem $id: startup.bat,v 1.4 2002/01/15 02:55:38 patrickl exp $
rem ---------------------------------------------------------------------------
rem guess catalina_home if not defined
if not "%catalina_home%" == "" goto gothome
set catalina_home=.
if exist "%catalina_home%/bin/catalina.bat" goto okhome
set catalina_home=..
:gothome
if exist "%catalina_home%/bin/catalina.bat" goto okhome
echo the catalina_home environment variable is not defined correctly
echo this environment variable is needed to run this program
goto end
:okhome
set executable=%catalina_home%/bin/catalina.bat
rem check that target executable exists
if exist "%executable%" goto okexec
echo cannot find %executable%
echo this file is needed to run this program
goto end
:okexec
rem get remaining unshifted command line arguments and save them in the
set cmd_line_args=
:setargs
if ""%1""=="""" goto donesetargs
set cmd_line_args=%cmd_line_args% %1
shift
goto setargs
:donesetargs
call "%executable%" start %cmd_line_args%
:end
我们可以清楚的看到这个文件需要读取系统变量catalina_home的值,所以我们在环境变数中把catalina_home设置为tomcat的安装路径就可以了。
3、启动、关闭tomcat
有2种方法可以启动、关闭安装好的tomcat:
① 直接点击运行bin目录下startup.bat和shutdown.bat文件就可以。
② 由于前面我们设置了path,所以我们直接在dos窗口中直接键入startup或shutdown亦可。
4、设置虚拟目录
编辑server文件(x:/tomcat/conf/server.xml)
因为在tomcat启动时要读取server文件的信息,所以更改server文件后,一定要重新启动tomcat。
举个例子:
我们打算建立一个myjsp的虚拟目录,只要在server.xml文件中加入如下代码即可:
<context path="/myjsp" docbase="c:/myjsp" debug="0"
reloadable="true" crosscontext="true">
</context>
其中,path为我们要建立的虚拟目录,docbase为实际目录在硬盘上的位置。
5、试我们前面工作的成果
编一个简单的小例子,来测试一下我们的虚拟目录是否可用。
refresh.jsp (c:/myjsp/refresh.jsp)
<%@page language="java"%>
<%@page import="java.util.date"%>
<html>
<head>
<title>auto refresh</title>
<%response.setheader("refresh","5");%>
</head>
<body bgcolor=#cc99dd><br>
<center><h1>auto refresh example</h1></center><br>
<center>refresh time : 5 sencords</center><br>
<center>now time is: <%=new date()%></center>
</body>
</html>
在地址栏键入http;//localhost:8080/myjsp/refresh.jsp,呵呵,看到效果了吧。
闽公网安备 35060202000074号