TOMCAT environment variable detailed configuration step _tomcat

Source: Internet
Author: User
Tags file copy tomcat

This example for you to share the Tomcat environment variable configuration tutorial for your reference, the specific content as follows

1.===> into the bin directory, double-click Startup.bat to see if the error. Generally will be reported.

2.===> My Computer ===> advanced ===> environment variable create a new variable named Java_home then the variable value is the upper level of your JDK's Bin directory. A new variable named Catalina_home variable value is the upper level of the directory of your Tomcat bin.

3.===> into the Tomcat bin directory, double-click Shutdown.bat and repeat 1. See if there is an error. Should not have reported it.

4.===> into the apache-tomcat-5.5.12\conf directory to locate the Tomcat-users.xml and then create a username password.
<user username= "admin" password= "123" roles= "Admin,manager"/>

5.===> then enters the Server.xml file in the Tomcat directory, finds connector port= "8080" and changes it to connector port= "8088"

The JDK+TOMCAT environment variable configuration is recorded in the blog, prepares for later use.

JDK environment variable configuration:
If your JDK is installed in C disk, such as: C:\j2sdk1.4.2_05, then in the system variable (and of course in the user variable) point to the new:
Variable Name: Java_home
Variable Value: C:\j2sdk1.4.2_05
Click New again:
variable name:classpath
variable value: ;%java_home%\lib\dt.jar;
and joined in the path.; %java_home%\bin;
Then your JDK has been configured successfully, of course, it is better to test whether the configuration is successful, then write a simple program to verify:

public class test{public
 
static void main{
 
  System.out.println ("successful")
 
}
 
}

Run the code, if there is no problem, then all OK, there is a problem, please check if the above write is wrong.

Tomcat environment variable configuration:
If your tomcat is installed in C disk, such as: F:\Tomcat50 (remember here, when installing Tomcat, there must be no spaces around its letters, or it may end up being configured unsuccessfully)
Again, in the system variable dot NEW:
Variable Name:Catalina_base
Variable Value:F:\Tomcat50;
New again:
Variable Name:Catalina_home
Variable Value:F:\Tomcat50;
Click OK to add%catalina_home%\common\lib\servlet-api.jar in classpath;
Add%catalina_home%\bin to Path;
Once you've made sure that your tomcat is configured, and also to verify that the configuration is successful, run Tomcat, click Start (or Start service), and then open the browser, typinghttp://localhost:8080, the configuration succeeds if the page appears.
Often see many people ask how to configure JDK and JSP, now I summarize the method, I hope to help.
First step:Download JDK and Tomcat
Step Two:Install and configure your JDK and Tomcat: Perform JDK and tomcat setup, and then set up the path to install.
1. After installing J2SDK, you need to configure the environment variables to add the following environment variables in My Computer-> properties-> Advanced-> environment variable-> system variable (assuming your JDK is installed in c:\jdk1.6):
java_home=c:\jdk1.6
Classpath=. ;%java_home%\lib\dt.jar;%java_home%\ Lib\tools.jar; (; must not be less because it represents the current path)
Path=%java_home%\bin
You can then write a simple Java program to test whether the JDK has been installed successfully:

public class test{public 
static void Main (String args[]) { 
System.out.println ("This is the Test program.");
 
}
 
}

The

Saves the above program as a file with a file name of Test.java.
then open the Command Prompt window, the CD to your Test.java directory, and then type the following command  
 javac Test.java
 java test 
At this point, if you see the print this are a test program, the installation is successful, if you do not print out this sentence, you need to carefully check your configuration.
 2. After installing Tomcat, add the following environment variables to my Computer-> properties-> the advanced-> environment variable-> system variable (assuming your Tomcat is installed in C: \tomcat):
  CATALINA_HOME:C: \tomcat
 catalina_base:c: \tomcat
 tomcat_home:c:\tomcat
  Then modify the environment variables in the CLASSPATH, the Tomat installation directory under the Common\lib Servlet.jar appended to the CLASSPATH, after the modified classpath as follows:  
classpath=.; %JAVA_HOME%\LIB\DT.JAR;%JAVA_HOME%\LIB\TOOLS.JAR;%CATALINA_HOME%\COMMON\LIB\SERVLET.JAR;&NBSP
can then start tomcat , accessing http://localhost:8080 in IE, if you see a Tomcat Welcome page, indicates that the installation was successful. &NBSP
Step Three: build your own JSP app directory  
1. To the WebApps directory of Tomcat's installation directory, you can see Root,examples, Tomcat-docs such as Tomcat's own directory;
2. Create a new directory under the WebApps directory, named MyApp;
3.myapp to create a new directory Web-inf, note that the directory name is case-sensitive;  
4.web-inf a new file Web.xml, which reads as follows: &NBSP

<?xml version= "1.0" encoding= "iso-8859-1"?> <! 
DOCTYPE Web-app public 
"-//sun Microsystems, INC.//DTD Web application 2.3//en" 
"http://java.sun.com/dtd/ Web-app_2_3.dtd "> 
<web-app> 
<display-name>my web application</display-name> 
<description> 
A application for test. 
</description> 
</web-app>

5. Under MyApp, create a new JSP page for the test, the file name is index.jsp, and the contents are as follows:

 
 

6. Restart Tomcat
7. Open the browser, enter http://localhost:8080/myapp/index.jsp to see the current time, the description is successful.
Step Fourth: Build Your own servlet:
Write to your first servlet

Import java.io.*; 
Import javax.servlet.*; 
Import javax.servlet.http.*; 
public class HelloWorld extends HttpServlet 
 {public 
  void doget (HttpServletRequest request, HttpServletResponse response) th 
rows servletexception,ioexception 
  { 
  response.setcontenttype ("text/ HTML "); 
  PrintWriter out = Response.getwriter (); 
  Out.println (" 
 

Then use Javac Helloworld.java to compile this file, if there is no import javax.servlet.*
Then it should be C:\Tomcat\common\lib inside the Servlet.jar file copy to the C:jdkjrelibext, compile again, there is no problem!
Then, in the C:\Tomcat\webapps\ROOT inside the Tomcat directory, press the following file structure:
Root\index.html
root\welcom.jsp
Root\web-inf\lib\myservlet.jar (If your servlet's. Class hits the. jar file, put it under Lib)
Root\web-inf\classes\helloworld.class (Put the Helloworld.class file that was generated above in this)
Then enter Http://localhost:8080/servlet/HelloWorld in the browser, so the server is expected to complain : Error 404--not Found What's going on?
The servlet must be registered using the Web.xml file below the C:\Tomcat\webapps\ROOT\WEB-INF directory,
Use EP to open this Web.xml file,
Put the following procedure
servlet>
.....
</servlet>
<servlet-mapping>
......
</servlet-mapping>
Replace into
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>

If not, just add the code directly, what?
Because of such a structure
<servlet> 
     <servlet-name>helloworld</ SERVLET-NAME>&NBSP
     <servlet-class>HelloWorld</servlet-class> 
</servlet> The
  represents the specified servlet class to include.
  The following structure
<servlet-mapping>
          <servlet-name>helloworld</servlet-name>
       <url-pattern> /SERVLET/HELLOWORLD</URL-PATTERN>&NBSP
</servlet-mapping>
Indicates which URL pattern the specified helloservlet should be mapped to.
After modifying the web.xml, restart the server and then enter Http://localhost:8080/servlet/HelloWorld , so a hello,world! I'm waiting for you.
  Add the following statement at the beginning of the JSP file to enable the Chinese name Display
  <%@ page language= "java" contenttype= text/ html charset=gb2312 "%>
  Modify Conf\server.xml to   in Tomcat directory;

port= "8080" maxthreads= "minsparethreads=" "maxsparethreads=" "enablelookups=" 
false "redirectport=" 8443 "acceptcount="
debug= "0" connectiontimeout= "20000" disableuploadtimeout= " 
true" uriencoding= " UTF-8 "/>

Note that the bold section is the place to modify, and you can make the Tomcat support the Chinese link later.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.