**********************************************
This post is searching from online, it is the best configuration guide I found to start JSP. The original author has not been determined, but thank you here. At the beginning, I traversed Tomcat English document. I still can't find a method of installing the installation configuration of Servlet (I have limited elevated levels), and later I saw this post. It is worth promoting.
**********************************************
J2SDK1.5 download address:
http://java.sun.com
Tomcat5.5 download address:
http://jakarta.apache.org/site/binindex.cgi
J2SDK1.5 installation directory: C: /J2SDK1.5.0
Tomcat5.5 installation directory: C: / Tomcat
1. Configure J2SDK1.5.0
1. Configuration underwindows 2000 Server Series
My Computer -> Properties -> Advanced -> Environmental Variables
Additional variable name: java_home Variable: C: /J2SDK1.5.0
Add variable name: Path Variable value:% java_home% / bin;
Add variable name: ClassPath down variable:.;% Java_home% / lib; or.;% Java_home% / lib / dt.jar;% java_home% / lib / Tools.jar
* Note: ".;" represents all references in the current directory, "% ...%" variable macro replacement.
2. Configuration under Windows 9x Series
Edit Autoexec.bat with Notepad, add the following statement:
Set java_home = c: /j2sdk1.5.0;
SET PATH =% PATH%;% java_home% / bin;
Set classpath =.;% Java_home% / lib; or.;% Java_home% / lib / dt.jar;% java_home% / lib / Tools.jar
3.Windows XP, 2003 Server configuration
The above two methods can be
4. Run
a. Edit the following code with Notepad and save to HelloWorld.java:
Public class helloworld {
Public static void main (String [] args) {
System.out.println ("Hello, World!");
}
}
b. Start -> Run -> cmd
Switch to the current directory in the console:
Javac HelloWorld.java
Java HelloWorld
You will see the output Hello, World!
* Note: Javac is a compiled command, which compiles helloWorld.java into HelloWorld.class
Java is explaining the command, and the JVM explains the HelloWorld.class.
To this Java run environment configuration, debugging is completed.
Second. Configure Tomcat5.5
1. Configuration underwindows 2000 Server Series
My Computer -> Properties -> Advanced -> Environmental Variables
Additional variable name: Tomcat_home Variable: C: / Tomcat
Additional variable name: ClassPath Under variable value:% Tomcat_Home% / Common / LIB;
2. Configuration under Windows 9x Series
Edit Autoexec.bat with Notepad, add the following statement:
Set tomcat_home = C: / Tomcat;
Set classpath =% classpath%;% Tomcat_home% / common / lib;
3. Windows XP, 2003 Server is configured with the above two methods
4. Run
Go to the C: / Tomcat / bin in the console, run startup.bat, then one window, even jump a big string, and finally the Server has run:
"Server Startup In ... MS"
Open the IE browser and enter: http:// localhost: 8080
At this point, the welcome interface has shown Tomcat is OK!
Go to the C: / Tomcat / bin in the console, run shutdown.bat, turn off the server.
To this Tomcat run environment configuration, debugging is completed.
3. Configuring javabeans
1. Edit the following code with Notepad and save to Circle.java:
Package abc.def;
Import java.io. *;
PUBLIC CLASS CIRCLE {
int RADIUS;
Public circle () {
RADIUS = 1;
}
Public int GetRadius () {
Return Radius;
}
Public void setRadius (int newradius) {
Radius = newradius;
}
Public double circlearea () {
Return Math.pi * Radius * Radius;
}
Public Double Circlelength () {
Return 2.0 * math.pi * radius;
}
}
2. Save Circle.java in a C: / Tomcat / Common / Classes / ABC / DEF directory.
3. Start -> Run -> cmd
Switch to the current directory in the console:
Javac circle.java or direct input Javac C: /tomcat/common/classes/abc/def/circle.java
4. Edit the following code with Notepad and save it as usebeans.jsp:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "abc.def.circle"%>
jsp: usebean>
<% girl.setradius (100);
%>
The radius of the circle is:
<% = girl.getradius ()%>
The circumference of the circle is:
<% = girl.circLength ()%>
The area of the circle is:
<% = girl.circlearea ()%>
Font>
Body>
Html>
5. Save UseBeans.jsp in the C: / Tomcat / WebApps / root directory.
6. After launching the server, open the IE browser and enter: http: // localhost: 8080 / usbeans.jsp
If the expected value, the JavaBeans configuration is successful!
"
The radius of the circle is: 100
The circumference of the circle is: 628.3185307179587 Round area is: 31415.926535897932
"
To this JavaBeans run environment configuration, debugging is completed.
4.Servlet configuration
1. Configuration underwindows 2000 Server Series
My Computer -> Properties -> Advanced -> Environmental Variables
Additional variable name: ClassPath Under variable value:% Tomcat_Home% / Common / lib / servlet-api.jar;
2. Configuration under Windows 9x Series
Edit Autoexec.bat with Notepad, add the following statement:
Set classpath =% classpath%;% Tomcat_Home% / common / lib / servlet-api.jar;
3.Windows XP, 2003 Server configuration
The above two methods can be
4. Run
a. Edit the following code with Notepad and save to Hello.java:
Import java.io. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public class hello extends httpservlet {
Public void init (servletconfig config) throws servletexception {
Super.init (config);
}
Public void service (httpservletRequest request, httpservletResponse response) throws oException {
PrintWriter out = response.getwriter ();
Response.setContentType ("text / html; charSet = GB2312");
Out.println ("
");OUT.PRINTLN ("Hello!");
Out.println (" Body> HTML>");
}
}
b. Save Hello.java in the C: / Tomcat / Common / Classes directory.
c. Start -> Run -> cmd
Switch to the current directory in the console:
Javac Hello.java or directly enter Javac C: /tomcat/common/classes/hello.java
D. Registration Servlet
Use Notepad to open C: /Tomcat/webapps/root/web-inf/web.xml
in
-
-
->
.
.
.
-
->
web-app>
The following two sets of data are added to the corresponding position:
servlet>
servlet-maping>
* Note:
C: / Tomcat / Common / Classes shared catalog, as well as:
C: / Tomcat / WebApps / Your application directory /Web-inf/web.xml
Registration, but must be added to C: / Tomcat / WebApps / under the application of servlets, such as:
Http: // localhost: 8080 / Your application catalog / servlet / hello
It is recommended that you apply the servlet class used by your own application to the C: / Tomcat / WebApps / your application directory / web-inf / class; in the web.xml registration servlet classpath is also "/ hello".
e. After restarting the server, open the IE browser and enter: http:// localhost: 8080 / servlet / hello
Display: "Hello!", The configuration is successful!
To this servlet run environment configuration, debugging is completed.
The above is the J2SDK1.5.0 Tomcat 5.5 (04.07.21) Configure environment steps. Since the Tomcat version is updated very fast, the configuration of each version is slightly different. I hope everyone can be flexible!
Here you emphasize a few considerations in this release:
1.javabeans enforce the introduction package package *. *;
2. Servlet class library is% Tomcat_Home% / Common / lib / servlet-api.jar
Not% Tomcat_Home% / lib / servlet.jar (there is no such directory and class library)
3. Introducing a third party library must be added to the ClassPath or add% java_home / lib / under normal loading. The * .jar file must be added to% tomcat_home / common / lib / lib / with TOMCAT5.5 (04.07.21).
This post only makes reference, the JSP configuration environment has many combinations, only mentioned J2SDK1.5.0 Tomcat5.5, but the foot is available, the intermediate developers are used! If you are inadequate in your post, please let me know, not grateful!