This example has shared a tutorial on the configuration of tomcat environment variables for your reference. The specific content is as follows
1.===> Enter the bin directory and double-click to see if the error is reported. I will generally report.
2.===> Right-click My Computer===>Advanced===>Environment Variable Create a new variable named JAVA_HOME and the variable value is the previous layer of your JDK's bin directory. Create another variable named CATALINA_HOME The variable value is the previous layer of your Tomcat bin directory.
3.===> Enter the Tomcat bin directory. Double-click and repeat the operation of 1. See if the error is reported. It shouldn't be reported.
4.===> Enter the apache-tomcat-5.5.12\conf directory and find it and create a username and password.
<user username="admin" password="123" roles="admin,manager"/>
5.===> Then enter the file under the conf directory in the Tomcat home directory, find the Connector port="8080" in it, and change it to Connector port="8088"
The jdk+tomcat environment variable configuration is recorded in the blog for later use.
JDK environment variable configuration:
If your JDK is installed in the C drive, such as: C:\j2sdk1.4.2_05, then click New in the system variable (of course you can also click on the user variable):
Variable name:JAVA_HOME
Variable value:C:\j2sdk1.4.2_05
Click New again:
Variable name:classpath
Variable value: ;%JAVA_HOME%\lib\;
And add .;%JAVA_HOME%\bin in the path;
Then your JDK is configured successfully. Of course, it is best to try again whether it is configured successfully. Then write a simple program to verify:
Public class Test{ public static void main{ ("successful") } }
Run the code, if there is no problem, everything is OK. If there is any problem, please check if the above is wrong.
Tomcat environment variable configuration:
If your Tomcat is installed on a C drive, such as: F:\Tomcat50 (remember here, when installing Tomcat, there must be no spaces around its letters, otherwise the configuration may be unsuccessful in the end)
Similarly, click New in the system variable:
Variable name:CATALINA_BASE
Variable value:F:\Tomcat50;
Create new again:
Variable name:CATALINA_HOME
Variable value:F:\Tomcat50;
Click OK and add %CATALINA_HOME%\common\lib\ to the classpath;
Add %CATALINA_HOME%\bin to path;
After confirming, your Tomcat is configured. To verify whether it is configured successfully, then run Tomcat, click Start (or Start service), open the browser and type inhttp://localhost:8080,If the page appears, the configuration is successful.
I often see many people asking how to configure JDK and JSP. Now I will summarize the methods, hoping that they will be helpful to everyone.
first step:Download jdk and tomcat
Step 2:Install and configure your jdk and tomcat: execute the jdk and tomcat installation program, and then set it to install it according to the path.
1. After installing j2sdk, you need to configure the environment variables and add the following environment variables to my computer->Properties->Advanced->Environment Variables->System variables (assuming that your jdk is installed in c:\jdk1.6):
JAVA_HOME=c:\jdk1.6
classpath=. ;%JAVA_HOME%\lib\;%JAVA_HOME%\ lib\; (;It must not be missing, because it represents the current path)
path=%JAVA_HOME%\bin
Then you can write a simple java program to test whether the JDK has been installed successfully:
public class Test{ public static void main(String args[]){ ("This is a test program."); } }
Save the above program as a file with the file name.
Then open the command prompt window, cd to your directory, and then type the following command
javac
java Test
If you see this is a test program printed at this time, it means that the installation has been successful. If this sentence is not printed, you need to carefully check your configuration.
2. After installing Tomcat, add the following environment variables to my computer -> Properties -> Advanced -> Environment Variables -> System Variables (assuming your tomcat is installed in c:\Tomcat):
CATALINA_HOME: C: \Tomcat
CATALINA_BASE: C: \Tomcat
TOMCAT_HOME: C:\Tomcat
Then modify the classpath in the environment variable, add the common\lib in the tomat installation directory to the classpath. The modified classpath is as follows:
classpath=.;%JAVA_HOME%\lib\;%JAVA_HOME%\lib\;%CATALINA_HOME%\common\lib\;
Then you can start tomcat and access it in IEhttp://localhost:8080, if you see the tomcat welcome page, it means that the installation has been successful.
Step 3:Create your own jsp app directory
1. Go to the webapps directory of Tomcat's installation directory and you can see the directories that Tomcat come with ROOT, examples, tomcat-docs, etc.;
2. Create a new directory under the webapps directory and name it myapp;
Create a new directory WEB-INF under. Note that the directory name is case sensitive;
- Create a new file under INF, with the content as follows:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "/dtd/web-app_2_3.dtd"> <web-app> <display-name>My Web Application</display-name> <description> A application for test. </description> </web-app>
5. Create a new test jsp page under myapp, with the file name as follows:
<html> <body> <center>Now time is: <%=new ()%></center> </body> </html>
6. Restart Tomcat
7. Open the browser and enterhttp://localhost:8080/myapp/If you see the current time, it means that it will be successful.
Step 4:Create your own Servlet:
Write to your first servlet
import .*; import .*; import .*; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response)th rows ServletException,IOException { ("text/html"); PrintWriter out = (); ("<html><head><title>"); ("This is my first Servlet"); ("</title></head><body>"); ("<h1>Hello,World!</h1>"); ("</body></html>"); } }
Then use javac to compile this file, if it does not import .*
Then you should copy the file in C:\Tomcat\common\lib to C:JDKjrelibext and compile it again, and there will be no problem!
Then, in the Tomcat directory C:\Tomcat\webapps\ROOT, the file structure is as follows:
ROOT\
ROOT\
ROOT\WEB-INF\lib\ (If your servlet's .class is typed into a .jar file, then put it under lib)
ROOT\WEB-INF\classes\(Put the file generated above in this)
Then enter in the browserhttp://localhost:8080/servlet/HelloWorld, So the server's expectations were wrong:Error 404--Not Found What's going on?
The Servlet must be registered using the file below C:\Tomcat\webapps\ROOT\WEB-INF.
Open this file with EP,
Put the following procedure
servlet>
.....
</servlet>
<servlet-mapping>
......
</servlet-mapping>
Replace with
<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 directly. What?
Because of this structure
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
Denotes the specified included servlet class.
And the following structure
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping>
Indicates which URL pattern to specify the HelloServlet should map to.
After the modification is completed, restart the Server and enterhttp://localhost:8080/servlet/HelloWorld, So big Hello, World! Waiting for you, congratulations on getting settled :)
Adding the following statement at the beginning of the JSP file can realize the Chinese name display
<%@ page language="java" contentType="text/html; charset=gb2312" %>
Modify the tomcat directory to conf\
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 the place to be modified. After modification, TOMCAT can support Chinese links.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.