Tomcat + JSP Classic Configuration Example

xiaoxiao2021-04-11  411

Tomcat JSP Classic Configuration Example

First, development environment configuration

Step 1: Download J2SDK and Tomcat: To Sun Official Station (http://java.sun.com/j2se/1.5.0/download.jsp) Download J2SDK, pay attention to the download version of the SDK for Windows Offline Installation, and best Download J2SE 1.5.0 Documentation, then download Tomcat official site (http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi) Download Tomcat (download the latest 5.5.9 version of Tomcat);

Step 2: Install and configure your J2SDK and Tomcat: Perform the J2SDK and Tomcat installer, then press the default settings.

1. After installing J2SDK, you need to configure the environment variable, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> System Variable (assuming your J2SDK installation in c: /j2sdk1.5.0):

Java_Home = C: /J2SDK1.5.0

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

Then you can write a simple Java program to test whether 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 file named Test.java file.

Then open the command prompt window, CD to your Test.java, and type the following command

Javac Test.java

Java Test

At this time, if you see the THIS A TEST Program. If you have successful installation, if you don't print this sentence, you need to check your configuration carefully.

2. After installing tomcat, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> 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 common / lib under the TOMAT installation directory (can be added according to the actual addition) servlet.jar 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;

You can then start Tomcat, access http: // localhost: 8080 in IE, if you see the Tomcat's welcome page, the installation is successful.

Step 3: Establish your own JSP app directory

1. To Tomcat's installation directory's webapps directory, you can see the directory of Tomcat's Tomcat, which root, example, tomcat-docs.

2. Create a directory in the webapps directory, named myapp;

3. New Catalog WEB-INF under MYApp, note that the directory name is case sensitive; 4. Web-infault new file web.xml, the content is as follows:

Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"

"http://java.sun.com/dtd/web-app_2_3.dtd">

My Web Application

A Application for Test.

5. Create a new test JSP page under MyApp, the file name is index.jsp, the file content is as follows:

Now Time Is: <% = new java.util.date ()%>

6. Restart Tomcat

7. Open the browser, enter http: // localhost: 8080 / myApp / index.jsp See the current time is successful.

Step 4: Establish your own servlet:

1. Use the editor you are most familiar with (it is recommended to use the Java IDE with syntax check), the file name is Test.java, the file content is as follows:

Package test;

Import java.io.ioException;

Import java.io.printwriter;

Import javax.servlet.servletException;

Import javax.servlet.http.httpservlet;

Import javax.servlet.http.httpservletRequest;

Import javax.servlet.http.httpservletResponse;

Public class test extends httpservlet {

Protected Void Doget (HttpservletRequest Request, HttpservletResponse Response)

Throws servletexception, ioException {

PrintWriter out = response.getwriter ();

Out.println ("

this is a servlet test. ");

Out.flush ();

}

}

2. Compilation

Put Test.java under C: / Test, compile the following command:

C: / test> javac test.java

Then generate a compiled servlet file under C: / Test: Test.class

3. Cut the structure Test / Test.class to% catalina_home% / WebApps / myApp / web-inf / class, that is, cut that Test directory to the class content, if the class content does not exist, will create a new one. Now WebApps / MyApp / Web-INF / CLASSES has a Test / Test.class file directory structure 4. Modify WebApps / MyApp / Web-INF / Web.xml, add servlet and servlet-mapping

The edited Web.xml as follows, red is added:

Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"

"http://java.sun.com/dtd/web-app_2_3.dtd">

My Web Application

A Application for Test.

test

Test

a test servlet

test.test

test

/ test

This paragraph declares that the servlet you want to call, and servlet-mapping is a represented servlet "mapping" to address / TEST

5. Ok, restart Tomcat, start the browser, enter http: // localhost: 8080 / myapp / test If you see the output this is a servlet test. The written servlet is successful.

Note: Modify Web.xml and new Class, you must restart Tomcat

Step 4: Establish your own bean:

1. Creating a Java program with the editor you are most familiar with (it is recommended to use the Java IDE with syntax), the file name is TestBean.java, the file content is as follows:

Package test;

Public class testbean {

Private string name = NULL;

Public TestBean (String Strname_P) {

THIS.NAME = STRNAME_P;

}

Public void setname (String strname_p) {

THIS.NAME = STRNAME_P;

}

Public string getname () {

Return this.name;

}

}

2. Compilation

Place TestBean.java in C: / Test, compile the following command: C: / test> Javac TestBean.java

Then generate a compiled bean file under C: / Test: TestBean.class

3. Cut the testbean.class file to% catalina_home% / WebApps / myapp / web-inf / classes / TEST,

4. Create a TestBean.jsp file, the file content is:

<% @ page import = "Test.TestBean"%>

<%

TestBean Testbean = New TestBean ("This Is A Test Java Bean);

%>

Java bean name is: <% = TestBean.getName ()%>

5. Ok, restart Tomcat, start the browser, enter http: // localhost: 8080 / myapp / testbean.jsp If you see the output Java Bean name is: this is a test java bean. The written bean is successful.

This completes the configuration of JSP, Servlet, and JavaBean under Tomcat. The next thing you need is to read more books, read more people's good code, yourself to write your code to enhance your ability to develop in this regard.

JVM should be filled out

C: / j2sdk / bin

Give you a simple configuration ::::

JSP environmental configuration experience

The first thing to say is, using JDK Tomcat to fully configure our JSP server, no longer need any stuff, there are many articles to introduce apache, in fact, there is no need to use, the general learning debug Tomcat is completely competent.

After installing JDK, Tomcat will automatically find the JDK installation path before installing, and click "Next". After a period of file copying, final "close", complete the COMCAT installation.

You'd better download a higher version of Tomcat, such as more than 4.1, because it does not need to set too much system variable, right click "My Computer", select "Properties" -> "->" environment variable "->" System Variable ", new Tomcat_Home, value set to your Tomcat where the path is located, such as: D: / Program Files / Apache Group / Tomcat 5.5, the configuration is completed.

From the start menu, find the Tomcat option, the order is: Start -> Program -> Apache Tomcat 5.5, select "Start Tomcat", let the JSP server start running, open a Window similar to the DOS, will display some related information. <

[2. After installing tomcat, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> System Variables (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 common / lib under the Tomat installation directory (can be added according to the actual addition) servlet.jar 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;

- The above servlet.jar seems to be servlet-api.jar in the new version.

转载请注明原文地址:https://www.9cbs.com/read-133509.html

New Post(0)