Tomcat configuration JSP, servlet, and JavaBean environment

Source: Internet
Author: User
Tags tomcat

Often see the JSP novice ask Tomcat How to configure the JSP, servlet and bean issues, so summed up how to configure the JSP, Servlet and Ben, in the hope of helping those beginners.

Step one: Download J2sdk and tomcat: Download J2SDK to the Sun official site (http://java.sun.com/j2se/1.4.2/download.html), note that the download version is Windows Offline Installation SDK, it is also best to download j2se 1.4.2 documentation and then to the Tomcat official site (http://www.apache.org/dist/jakarta/tomcat-4/ Download tomcat (Download the latest 4.1.x version of Tomcat);

Step Two: Install and configure your J2SDK and Tomcat: Perform J2SDK and tomcat setup, and then install it by default settings.

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 j2sdk is installed in c:\j2sdk1.4.2):

JAVA_HOME=c:\j2sdk1.4.2
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因为它代表当前路径)
path=%JAVA_HOME%\bin

You can then write a simple Java program to test whether the J2SDK 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 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 in My Computer-> properties-> Advanced-> environment variable-> system variable (assuming your Tomcat is installed in C:\tomcat):

Catalina_home=c:\tomcat;

Catalina_base=c:\tomcat;

Then modify the classpath in the environment variable, add the Servlet.jar under the Tomat installation directory to classpath, and modify Classpath as follows:

Classpath=.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar;%catalina_home%\common\lib\servlet.jar;

Then you can start Tomcat, access http://localhost:8080 in IE, and if you see the Tomcat Welcome page, the installation is successful.

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 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:

<?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:

Now time is: <%=new java.util.Date()%>
</center></body>

Related Article

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.