Detailed configuration steps for tomcat environment variables
- 2020-05-15 03:00:28
- OfStack
For your reference, this article shares the tomcat environment variable configuration tutorial as an example. The details are as follows
1.===
>
Enter the bin directory and double-click startup.bat to see if there is an error. I'm sure it will.
2.===
>
Right click on my computer ===
>
Senior = = =
>
The environment variable creates a new variable called JAVA_HOME and the value of the variable is one layer above your JDK bin directory. Create a new variable called CATALINA_HOME and the value is one layer above your Tomcat bin directory.
3.===
>
Go to Tomcat bin and double click shutdown.bat and repeat 1. See if there is an error. It should stop.
4.===
>
Go to apache-tomcat-5.5.12 \conf and find tomcat-users.xml and create a username and password.
<
user username="admin" password="123" roles="admin,manager"/
>
5.===
>
Then go to the server.xml file in the conf directory in the Tomcat home directory, find Connector port="8080", and change it to Connector port="8088"
The jdk+tomcat environment variable configuration records 1 in blog for later use.
JDK environment variable configuration:
If your JDK is installed on the C disk, such as: C:\ j2sdk1.4.2_05, then in the system variable (and of course in the user variable) click 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 add... to path; JAVA_HOME % % \ bin;
Then your JDK will be configured successfully. Of course, it is better to test again whether the configuration is successful or not. Then write a simple program to verify 1:
Public class Test{
public static void main{
System.out.println("successful")
}
}
Run the code. If there is no problem, then 1 cut OK. If there is a problem, please check whether what is written above 1 is wrong.
Tomcat environment variable configuration:
If your Tomcat is installed on the C drive, e.g. F:\Tomcat50 (remember here 1, when installing Tomcat, there must be no space around the letters 1, otherwise the configuration may end up unsuccessful)
Similarly, in the system variable, click new:
Variable name: CATALINA_BASE
Variable value: F:\Tomcat50;
New again:
Variable name: CATALINA_HOME
Variable value: F:\Tomcat50;
Click ok and add %CATALINA_HOME%\common\lib\ servlet-api. jar;
Add %CATALINA_HOME%\bin;
Once confirmed, your Tomcat is ready to be configured. Also, to verify the successful configuration, run Tomcat. After launching (or Start service), open the browser and type http://localhost:8080.
I often see many people ask how to configure JDK and JSP, now I will summarize the method, I hope to help you.
Step 1: download jdk and tomcat
Step 2: install and configure your jdk and tomcat: execute the installation program for jdk and tomcat, then set up the installation path.
1. After installing j2sdk, you need to configure 1 environment variable on my computer -
>
Property -
>
Advanced -
>
Environmental variables -
>
Add the following environment variables to the system variables (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; (; 1 must not be less, because it represents the current path.)
path=%JAVA_HOME%\bin
You can then write a simple java program to test if JDK has been installed successfully:
public class Test{
public static void main(String args[]){
System.out.println("This is a test program.");
}
}
Save the above program as a file called Test.java.
Then open the command prompt window, cd to the directory where your Test.java is located, and type the following command
javac Test.java
java Test
At this point, if you see This is a test program, it means that the installation is successful. If you do not print this sentence, you need to carefully check your configuration.
2. After installing Tomcat on my computer -
>
Property -
>
Advanced -
>
Environmental variables -
>
Add the following environment variables to the system variables (assuming your tomcat is installed at c: \Tomcat) :
CATALINA_HOME: C: \Tomcat
CATALINA_BASE: C: \Tomcat
TOMCAT_HOME: C:\Tomcat
Then modify classpath in the environment variable and append servlet under common\lib in the tomat installation directory to classpath.jar is appended to classpath. The modified classpath is as follows:
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\common\lib\servlet.jar;
You can then launch tomcat and access http://localhost:8080 from IE. If you see the welcome page for tomcat, the installation was successful.
Step 3: create your own jsp app directory
1. Go to the webapps directory of the installation directory of Tomcat, and you can see the ROOT, examples, tomcat-docs and other directories that come with Tomcat;
2. Create a new directory under webapps and call it myapp;
3. Create a new directory WEB-INF under myapp. Note that the directory name is case sensitive.
4. Create a new file web. xml under WEB-INF, which reads as follows:
<?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.
<html>
<body>
<center>Now time is: <%=new java.util.Date()%></center>
</body>
</html>
6. Restart Tomcat
7. Open a browser and enter http: / / localhost: 8080 / myapp index jsp see the instructions for the current time is successful.
Step 4: create your own Servlet:
Write 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("<html><head><title>");
out.println("This is my first Servlet");
out.println("</title></head><body>");
out.println("<h1>Hello,World!</h1>");
out.println("</body></html>");
}
}
Then compile the file with javac HelloWorld.java.* if you cannot import javax.servlet
Then the C:\Tomcat\common\ jar file should be copied to C:JDKjrelibext and compiled again. No problem!
Then in the Tomcat directory C:\Tomcat\webapps\ROOT file structure as follows:
ROOT\index.html
ROOT\welcom.jsp
ROOT\ WEB-INF \lib\ MyServlet. jar (if your servlet.class is typed as.jar)
ROOT\ WEB-INF \classes\ HelloWorld.class (put the HelloWorld.class file generated above in this file)
Then in the browser input http: / / localhost: 8080 / servlet/HelloWorld, hence Server incumbent error: 404 - Error Not Found how to return a responsibility?
Servlet must be registered with C:\Tomcat\webapps\ROOT\ WEB-INF file under this directory, web.xml,
Open this web.xml file with EP,
So let's take the following program
servlet
>
.....
<
/servlet
>
<
servlet-mapping
>
......
<
/servlet-mapping
>
replace
<
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 that code. What?
Because of the structure
<
servlet
>
<
servlet-name
>
HelloWorld
<
/servlet-name
>
<
servlet-class
>
HelloWorld
<
/servlet-class
>
<
/servlet
>
Represents the servlet class to be included.
And the following structure
<
servlet-mapping
>
<
servlet-name
>
HelloWorld
<
/servlet-name
>
<
url-pattern
>
/servlet/HelloWorld
<
/url-pattern
>
<
/servlet-mapping
>
Specifies which URL schema HelloServlet should be mapped to.
In modified web. xml after finished, restart the Server, then input http: / / localhost: 8080 / servlet/HelloWorld, so large a Hello, World! I'm waiting for you. Congratulations
Add the following statement at the beginning of JSP file to display the Chinese name
<
%@ page language="java" contentType="text/html; charset=gb2312" %
>
Modify conf\server.xml is
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="UTF-8"/>
Note that the bold part is where the changes are made, so that TOMCAT can support Chinese links.