1. ==> go to the bin directory and double-click STARTUP. BAT to check whether an error is returned. Generally, it will be reported.
2. Right-click my computer ==> advanced ==> environment variable to create a variable named java_home and the variable value is the upper layer of your JDK bin directory. Create a variable named catalina_home whose value is the upper layer of your Tomcat bin directory.
3. ==> double-click shutdown. bat under the Tomcat bin directory and repeat the 1 operation. Check whether an error is returned. It should not be reported.
4. ==> go to the Apache-Tomcat-5.5.12 \ conf directory and find the tomcat-users.xml and create a username and password.
<User Username = "admin" Password = "123" roles = "Admin, Manager"/>
5. then go to the server under the conf directory in the Tomcat main directory. XML file, find connector Port = "8080" and change it to connector Port = "8088"
Configure the JDK + Tomcat environment variables in the blog for later use.
JDK environment variable Configuration:
If your JDK is installed on drive C, for example, C: \ j2sdk1.4.2 _ 05, you can click New in the system variable (or in 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 \ DT. jar;
Add.; % java_home % \ bin in path;
Then your JDK configuration is successful. Of course, it is best to test whether the configuration is successful. Then, write a simple program to verify it:
Public class test {
Public static void main {
System. Out. println ("successful ")
}
}
Run the Code. If there is no problem, everything is OK. If there is a problem, check whether there is a mistake in the above.
Tomcat environment variable Configuration:
If your Tomcat is installed on drive C, for example, F: \ tomcat50 (remember that there must be no space around its letters during tomcat installation, otherwise, the configuration may fail)
Similarly, click New in the system variable:
Variable name: catalina_base
Variable value: F: \ tomcat50;
Create again:
Variable name: catalina_home
Variable value: F: \ tomcat50;
Click OK and add % catalina_home % \ common \ Lib \ servlet-api.jar to classpath;
Add % catalina_home % \ bin to path;
After confirming, your Tomcat is configured. to verify whether the configuration is successful, run tomcat, click Start service, open the browser, and enter http: // localhost: 8080. If a page is displayed, the configuration is successful.
I often see many people asking how to configure JDK and JSP. Now I will summarize the methods and hope to help you.
Step 1: Download JDK and tomcat
Step 2: install and configure your JDK and tomcat: Execute the JDK and tomcat installation programs, and then set the installation according to the path.
1. after installing j2sdk, You need to configure the environment variables, add the following environment variables to my computer> Properties> advanced> environment variables> 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; (.; must not be small, because it represents the current path)
Path = % java_home % \ bin
Then, you can write a simple Java program to test whether 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 named test. java.
Then open the Command Prompt window, CD to the directory where your test. Java is located, and then type the following command
Javac test. Java
Java Test
If this is a test program is printed, the installation is successful. If this is not printed, You need to carefully check your configuration.
2. after Tomcat is installed, 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
Modify the classpath in the environment variable and append the servlet. Jar under the common \ Lib under the Tomat installation directory to the classpath. The modified classpath is as follows:
Classpath =.; % java_home % \ Lib \ DT. jar; % java_home % \ Lib \ tools. jar; % catalina_home % \ common \ Lib \ servlet. jar;
Start Tomcat and access http: // localhost: 8080 in IE. If you see the welcome page of Tomcat, the installation is successful.
Step 3: Create your own JSP app directory
1. Go to the webapps directory of the tomcat installation directory, and you can see the Tomcat built-in directories such as root, examples, and tomcat-docs;
2. Create a directory named MyApp under the webapps directory;
3. Create a directory WEB-INF under MyApp, note that the directory name is case sensitive;
4. Create a file web. xml under the WEB-INF with the following content:
<? 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. Create a test JSP page under MyApp. The file name is index. jsp. The file content is as follows:
<HTML> <body> <center> now time is: <% = new java. util. Date () %> </center> </body>
6. Restart Tomcat
7. Open the browser and enter http: // localhost: 8080/MyApp/index. jsp to view the current time.
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>
Out. println ("this is my first servlet ");
Out. println ("</title>
Out. println ("
Out. println ("</body>
}
}
Then use javac helloworld. Java to compile the file. If the file cannot be imported javax. servlet .*
Then, we should copy the servlet. JAR file in c: \ Tomcat \ common \ Lib to C: jdkjrelibext and compile it again!
Then, in the Tomcat directory c: \ Tomcat \ webapps \ Root, follow the following file structure:
Root \ index.html
Root \ Welcom. jsp
Root \ WEB-INF \ Lib \ myservlet. Jar (If your servlet. Class is typed into a. jar file, put it under Lib)
Root \ WEB-INF \ Classes \ helloworld. Class (put the above generated helloworld. Class file in this)
Then, enter http: // localhost: 8080/servlet/helloworld in the browser. The Error 404 -- not found is returned by the server?
Servlet must be registered using the web. xml file under the directory c: \ Tomcat \ webapps \ Root \ WEB-INF,
Open the Web. xml file with EP,
Set the following procedure
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, add the Code directly.
Why?
Because of this structure
<Servlet>
<Servlet-Name> helloworld </servlet-Name>
<Servlet-class> helloworld </servlet-class>
</Servlet>
Indicates the specified servlet class.
The following structure
<Servlet-mapping>
<Servlet-Name> helloworld </servlet-Name>
<URL-pattern>/servlet/helloworld </url-pattern>
</Servlet-mapping>
Specifies the URL mode to which helloservlet maps.
After modifying web. XML, restart the server and then enter http: // localhost: 8080/servlet/helloworld. Then, a large Hello, world! Waiting for you. Congratulations! You're done :)
Add the following statement at the beginning of the JSP file to display the Chinese name
<% @ Page Language = "Java" contenttype = "text/html; charset = gb2312" %>
Modify conf \ Server. XML in the Tomcat directory
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 simhei part is modified. After modification, Tomcat can support Chinese links.
The above is the complete configuration method. You can also use tomcat to support Chinese characters. In fact, it is available in my space.