RHEL4系统中JDK+Tomcat开发环境的简单实现
2007-06-12 kenthy#qingdaonews.com
######################################
系统环境:RHEL4 [ 2.6.9-5.EL ]
软件版本:
jdk-1_5_0_05-linux-i586.bin
jakarta-tomcat-5.5.9.tar.gz
jakarta-tomcat-5.5.9-admin.tar.gz
######################################
一、安装jdk-1_5_0_05-linux-i586.bin
1、解包安装
# mv jdk-1_5_0_05-linux-i586.bin /usr/local/
# cd /usr/local
# chmod +x jdk-1_5_0_05-linux-i586.bin
# ./jdk-1_5_0_05-linux-i586.bin
2、设置环境
# ln -s /usr/local/jdk-1.5.0_05 /usr/local/jdk
# vi /etc/profile //添加以下内容
JAVA_HOME=/usr/local/jdk
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVAHOME/lib/tools.jar:$CLASSPATH
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
# `tail -4 /etc/profile` //执行上述设置的四行命令
# ln -sf /usr/local/java/jdk1.5.0_05/bin/java /usr/bin/
# ln -sf /usr/local/java/jdk1.5.0_05/bin/javac /usr/bin/
3、验证jdk安装
# java -version //查看java版本
# vi HelloWorld.java //创建简单的java程序,内容如下
import java.io.*;
public class HelloWorld {
public static void main( String args[] ) {
System.out.println("HelloWorld!!");
}
}
# javac HelloWorld.java //测试javac的编译功能
# java HelloWorld //测试java程序的运行
二、安装tomcat
1、解包安装并设置环境
# tar zxvf jakarta-tomcat-5.5.9.tar.gz -C /usr/local/
# tar zxvf jakarta-tomcat-5.5.9-admin.tar.gz -C /usr/local/
# ln -s /usr/local/jakarta-tomcat-5.5.9 /usr/local/tomcat
# export CATALINA_HOME=/usr/local/tomcat //设置CATALINA_HOME变量并用export导出
# echo 'export CATALINA_HOME=/usr/local/tomcat' >> /etc/profile
2、添加管理员用户
# vi /usr/local/tomcat/conf/tomcat-users.xml //添加一行设置,增加管理员用户kenthy
3、启动服务并访问测试
# ln -s /usr/local/tomcat/bin/shutdown.sh /usr/bin/tomcat-down
# ln -s /usr/local/tomcat/bin/startup.sh /usr/bin/tomcat-up
# tomcat-up //启动tomcat服务
在浏览器里访问 //若看到tomcat欢迎界面则启动正常
通过欢迎界面左侧栏里的链接可以测试jsp及servlet基本功能
访问可以使用kenthy登陆进行管理
4、测试简单的自建jsp页面
# mkdir /usr/local/tomcat/webapps/accp
# vi /usr/local/tomcat/webapps/accp/showtime.jsp
< language="java" import="java.util.*"%>
Now Time is : <%out.println(new Date());%>
在浏览器里访问 //若显示系统时间则正常
5、测试简单的自建Servlet
# cd /usr/loca/tomcat/webapps
# cp -rf servlets-examples/WEB-INF accp/
# cd accp/WEB-INF/classes
# rm -rf *.* //删除多余的文件
# vi HelloServlet.java //创建servlet源文件
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("
Hello Servlet World!
");
}
}
# javac HelloServlet.java
# vi ../web.xml //修改web.xml添加映射
"">
HelloServlet
HelloServlet
HelloServlet
/servlet/*
# tomcat-down ; tomcat-up //重启tomcat服务程序
在浏览器里访问 //若显示"Hello Servlet World!"则自建servlet正常
阅读(1513) | 评论(0) | 转发(0) |