标签:tomcat
/==============================基本安装使用=========================================>/
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html下载JDK
1.1安装jdk
~]# rpm -ivh jdk-7u67-linux-x64.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
jfxrt.jar...
~]# vi /etc/profile.d/java.sh
~]# source /etc/profile.d/java.sh
~]# java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build24.65-b04, mixed mode)
http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.57.tar.gz
~]# tar xf apache-tomcat-7.0.57.tar.gz -C/usr/local/
~]# cd /usr/local/
创建连接
]# ln -sv apache-tomcat-7.0.57 tomcat
`tomcat‘ -> `apache-tomcat-7.0.57‘
]# useradd -M -d /usr/local/tomcat tomcat ]# chown -R tomcat /usr/local/tomcat* |
]# vim /etc/rc.d/init.d/tomcat #!/bin/bash
# Tomcat7: Start/Stop Tomcat 7 # # chkconfig: - 90 10 # description: Tomcat is a Java application Server.
. /etc/init.d/functions . /etc/sysconfig/network
CATALINA_HOME=/usr/local/tomcat TOMCAT_USER=tomcat
LOCKFILE=/var/lock/subsys/tomcat
RETVAL=0 start(){ echo "Starting Tomcat7: " su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCKFILE return $RETVAL }
RETVAL=0 start(){ echo "Starting Tomcat: " su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCKFILE return $RETVAL }
stop(){ echo "Shutting down Tomcat: " $CATALINA_HOME/bin/shutdown.sh RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $LOCKFILE return $RETVAL }
case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $? |
]# chmod 755 /etc/rc.d/init.d/tomcat
l]# /etc/rc.d/init.d/tomcat start Starting Tomcat: Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/default Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. |
]# chkconfig --add tomcat
]# chkconfig tomcat on
]# chkconfig--list tomcat
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
]# mkdir -pv /usr/local/tomcat/webapps/ROOT/WEB-INF/classes mkdir: created directory `/usr/local/tomcat/webapps/ROOT/WEB-INF/classes‘
修改属主 ]# chown tomcat . /usr/local/tomcat/webapps/ROOT/WEB-INF/classes
]# cd /usr/local/tomcat/webapps/ROOT/WEB-INF/classes 创建自定义的主页面 ]#vim daytime.java |
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.Calendar;
public class daytime extends HttpServlet { public void doGet(HttpServletRequest request ,HttpServletResponse response)
throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); Calendar cal = Calendar.getInstance(); out.println("<html>\n<head>\n<title>DayTime-TomcatA</title>\n</head>\n<body>"); out.println("<div style=\"font-size: 40px; text-align: center; font-weight: bold\">"); out.println(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE)); out.println("</div>\n</body>\n</html>"); } } |
]# javac -classpath /usr/local/tomcat/lib/servlet-api.jar daytime.java |
]# vim /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml [root@TomcatA classes]# cat /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!-- 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. -->
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true">
<display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- start--> <servlet> <servlet-name>daytime</servlet-name> <servlet-class>daytime</servlet-class> </servlet> <servlet-mapping> <servlet-name>daytime</servlet-name> <url-pattern>/daytime</url-pattern> </servlet-mapping> <!-- end--> </web-app> |
~]# rpm -ivh jdk-7u67-linux-x64.rpm Preparing... ########################################### [100%] 1:jdk ########################################### [100%] Unpacking JAR files... rt.jar... jsse.jar... charsets.jar... tools.jar... localedata.jar... jfxrt.jar... |
~]# vim /etc/profile.d/java.sh export JAVA_HOME=/usr/java/default export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar |
~]# source /etc/profile.d/java.sh ~]# java -version java version "1.7.0_67" Java(TM) SE Runtime Environment (build 1.7.0_67-b01) Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode) |
[root@TomcatB ~]# tar xf apache-tomcat-7.0.57.tar.gz -C /usr/local/ [root@TomcatB ~]# cd /usr/local/ 创建软连接 [root@TomcatB local]# ln -sv apache-tomcat-7.0.57 tomcat `tomcat‘ -> `apache-tomcat-7.0.57‘ |
[root@TomcatB local]# useradd -M -d /usr/local/tomcat tomcat [root@TomcatB local]# chown -R tomcat /usr/local/tomcat* |
]# vim /etc/rc.d/init.d/tomcat #!/bin/bash
# Tomcat7: Start/Stop Tomcat 7 # # chkconfig: - 90 10 # description: Tomcat is a Java application Server.
. /etc/init.d/functions . /etc/sysconfig/network
CATALINA_HOME=/usr/local/tomcat TOMCAT_USER=tomcat
LOCKFILE=/var/lock/subsys/tomcat
RETVAL=0 start(){ echo "Starting Tomcat7: " su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCKFILE return $RETVAL }
RETVAL=0 start(){ echo "Starting Tomcat: " su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh" RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $LOCKFILE return $RETVAL }
stop(){ echo "Shutting down Tomcat: " $CATALINA_HOME/bin/shutdown.sh RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $LOCKFILE return $RETVAL }
case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $? |
]# chmod 755 /etc/rc.d/init.d/tomcat
]# /etc/rc.d/init.d/tomcat start Starting Tomcat: Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr/java/default Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started.
|
]# chkconfig --add tomcat
]# chkconfig tomcat on ]# chkconfig --list tomcat tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off |
]# mkdir -pv /usr/local/tomcat/webapps/ROOT/WEB-INF/classes mkdir: created directory `/usr/local/tomcat/webapps/ROOT/WEB-INF/classes‘ 修改属主 ]# chown tomcat . /usr/local/tomcat/webapps/ROOT/WEB-INF/classes 创建自定义主页 ]# cd /usr/local/tomcat/webapps/ROOT/WEB-INF/classes ]#vim daytime.java |
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.Calendar;
public class daytime extends HttpServlet { public void doGet(HttpServletRequest request ,HttpServletResponse response)
throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); Calendar cal = Calendar.getInstance(); out.println("<html>\n<head>\n<title>DayTime-TomcatB</title>\n</head>\n<body>"); out.println("<div style=\"font-size: 40px; text-align: center; font-weight: bold\">"); out.println(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE)); out.println("</div>\n</body>\n</html>"); } } |
编译 ]# javac -classpath /usr/local/tomcat/lib/servlet-api.jar daytime.java |
]# vim /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!-- 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. -->
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true">
<display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <!-- Start 以下为添加的内容--> <servlet> <servlet-name>daytime</servlet-name> <servlet-class>daytime</servlet-class> </servlet> <servlet-mapping> <servlet-name>daytime</servlet-name> <url-pattern>/daytime</url-pattern> </servlet-mapping>
<!-- End 结束分割线********--> </web-app> |
http://down.51cto.com/data/2113380
本文出自 “To live is to die” 博客,请务必保留此出处http://7431686.blog.51cto.com/7421686/1708386
标签:tomcat
原文地址:http://7431686.blog.51cto.com/7421686/1708386