Jdk+tomcat Classic Configuration

Source: Internet
Author: User
J2SE is the standard version of JAVA2, mainly for desktop application software programming;
J2ME is mainly used in embedded system development, such as mobile phone and PDA programming;
Java EE is the Enterprise version of JAVA2, mainly for the development of distributed network programs, such as E-commerce website and ERP system.

The JDK (Java Develop Kit,java Development toolkit) provides a Java development environment and operating environment, primarily for Java programs and Java program developers;
The JRE (Java Runtime Environment,java Runtime Environment) provides a Java operating environment that is primarily used to execute Java programs and target users of Java programs.
Typically, each JDK contains two sets of JRE. Take the JDK jdk1.6.0_22 (the default installation path is E:\Program Files\java), for example, in E:\Program
There is a JRE under the Files\java\jdk1.6.0_22\ directory, and a JRE under the C:\Program files\java\ directory. Why there are two sets of JRE. Because the JDK
Inside the tools are also written in Java, they also need a set of JRE when running, that is, E:\Program files\java\jdk1.6.0_22\ directory of the JRE. and
The JRE under the E:\Program files\java\ directory is used to execute the Java program that we write ourselves. Of course, any of the two sets of JRE can be used to execute our own
Written Java programs, but the tools within the JDK can only be executed by the JRE under the E:\Program files\java\jdk1.6.0_22\ directory.



There are several versions of JDK installed on the machine, to start eclipse with the specified JDK, just modify the Eclipse.ini file.

Reference:

-vm
C:/jdk1.6.0_18/bin/javaw.exe (//--Note: Put the first line)
--launcher. Xxmaxpermsize
256m
-vmargs
-xms128m
-xmx512m


Path path is where the Java compile-time program (such as JAVA,JAVAC, etc.) needs to be invoked.
The path of the Classpath class, when compiling a Java program, to find the desired class in the classpath if there is a call to another class.


Jdk+tomcat Classic Configuration


1. Path environment variable: function to specify a command search path, execute a command under the I command line if Javac compiles a Java program, it looks in the path specified by the path variable to see if the appropriate command program can be found. We need to add the bin directory in the JDK installation directory to the existing path variable, the bin directory contains the frequently used executable files such as Javac/java/javadoc wait, after setting the path variable, you can execute Javac/java tools in any directory.

2. CLASSPATH environment variables: The role is to specify the class search path, to use the class has been written, the premise of course is to be able to find them, the JVM is through the classpth to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory under the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable.

3. Java_home environment variable: It points to the installation directory of JDK, Eclipse/netbeans/tomcat software is to search Java_home variables to find and use the installed JDK.
I. Configuring j2sdk1.5.0
1.Windows Server Series Configuration
My Computer-> Properties-> Advanced-> Environment variables
Append variable name: Java_home variable Value: C:\j2sdk1.5.0
Append variable Name: PATH variable value:%java_home%\bin;
Append variable name: Classpath variable value:.; %java_home%\lib, or.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar
* Note: ".;" Represents all references under the current directory, and "%...%" variable macros are replaced.

2.Windows 9x Series Configuration
Edit Autoexec.bat with Notepad and 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
Both of the above methods can be

4. Run

A. Edit the following code in Notepad and save it as Helloworld.java:
public class helloworld{
public static void Main (string[] args) {
System.out.println ("hello,world!");
}
}

B. Start-> run->cmd
To switch to the current directory in the console:
Javac Helloworld.java
Java HelloWorld
You'll see the output hello,world! on the console.

* Note: Javac is the compiler command, it compiles helloworld.java into Helloworld.class
Java is the interpretation command, the JVM interprets the Helloworld.class to execute
This is the Java run environment configuration, debugging completed.

Two. Configure tomcat5.5
1.Windows Server Series Configuration
My Computer-> Properties-> Advanced-> Environment variables
Append variable name: Tomcat_home variable Value: C:\tomcat
Append variable name: Classpath variable value:%tomcat_home%\common\lib;

2.Windows 9x Series Configuration
Edit Autoexec.bat with Notepad and add the following statement:
SET Tomcat_home=c:\tomcat;
SET Classpath=%classpath%;%tomcat_home%\common\lib;

3.Windows XP, 2003 server Configuration
Both of the above methods can be

4. Run
In the console, go to the C:\tomcat\bin directory, run Startup.bat, and then a window will appear, jumping a bunch of things, and finally indicates that the server is running:
"Server Startup in ... MS"
Open IE browser and enter in the Address bar: http://localhost:8080
The welcome interface at this point indicates that Tomcat is OK.
Go to the C:\tomcat\bin directory in the console, run Shutdown.bat, and shut down the server.
At this point tomcat is running environment configuration, debugging complete.

Three. Configure JavaBeans

1. Edit the following code in Notepad and save it as 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 the Circle.java in the C:\tomcat\common\classes\abc\def directory.

3. Start-> Run->cmd
To 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 in Notepad and save it as usebeans.jsp:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "Abc.def.Circle"%>
<HTML>
<body bgcolor=cyan>
<font size=1>
<jsp:usebean id= "Girl" class= "abc.def.Circle" scope= "page" >
</jsp:useBean>
<% Girl.setradius (100);
%>
The radius of the <P> circle is:
<%= Girl.getradius ()%>
The circumference of the <P> circle is:
<%= girl.circlelength ()%>
The area of <P> Circle is:
<%= Girl.circlearea ()%>
</FONT>
</BODY>
</HTML>

5. Save the usebeans.jsp in the C:\tomcat\webapps\ROOT directory.

6. After starting the server, open IE browser and enter in the Address bar: http://localhost:8080/useBeans.jsp
If the expected value appears, the JavaBeans configuration is successful.

The radius of the circle is: 100

Circumference of the circle is: 628.3185307179587

The area of the circle is: 31415.926535897932

This JavaBeans to run the environment configuration, debugging completed.

Four. servlet configuration
1.Windows Server Series Configuration
My Computer-> Properties-> Advanced-> Environment variables
Append variable name: Classpath variable value:%tomcat_home%\common\lib\servlet-api.jar;

2.Windows 9x Series Configuration
Edit Autoexec.bat with Notepad and add the following statement:
SET Classpath=%classpath%;%tomcat_home%\common\lib\servlet-api.jar;

3.Windows XP, 2003 server Configuration
Both of the above methods can be

4. Run
A. Edit the following code in Notepad and save it as 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 ioexception{
PrintWriter Out=response.getwriter ();
Response.setcontenttype ("text/html;charset=gb2312");
Out.println ("<HTML><BODY>");
Out.println ("hello!");
Out.println ("</BODY></HTML>");
}
}

B. Save the Hello.java in the C:\tomcat\common\classes directory.

C. Start-> run->cmd
To switch to the current directory in the console:
Javac Hello.java or direct input Javac C:\tomcat\common\classes\Hello.java

D. Registering a servlet
Open C:\tomcat\webapps\ROOT\WEB-INF\web.xml with Notepad
In
-<web-app xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: Schemalocation= "Http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; version= "2.4" >
<display-name>welcome to Tomcat</display-name>
<description>welcome to Tomcat</description>
-<!--jspc servlet mappings Start
-->
.
.
.
-<!--JSPC servlet mappings End
-->
</web-app>
Append the following two sets of data to the appropriate location:
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/servlet/Hello</url-pattern>
</servlet-mapping>

* Note:<servlet-name>...</servlet-name> as the ID of the servlet in the server
<servlet-class>...</servlet-class> for Servlet-class class name
<url-pattern>...</url-pattern> for mirrored path and virtual path
C:\tomcat\common\classes is a shared directory for the class and can also be:
C:\tomcat\webapps\ Your application directory \web-inf\web.xml
, but when you apply the servlet, you must include the directory name under C:\tomcat\webapps\, such as:
http://localhost:8080/Your application directory/servlet/hello
It is recommended that you apply your own servlet class to C:\tomcat\webapps\ your application directory \web-inf\classes, and that the Web.xml registration servlet classpath is also "/hello".

E. After restarting the server, open IE browser and enter in the Address bar: Http://localhost:8080/servlet/Hello
Display: "Hello!", the configuration is successful.
This servlet runs the environment configuration, debugging complete.

The above is the j2sdk1.5.0+tomcat5.5 (04.07.21) configuration environment step. Because the Tomcat version is updated very quickly, there are slightly different configurations for each version. I hope you can be flexible.

Here are some caveats to this release:
1.javabeans forced to introduce package package *.*;
2.servlet Class Library for%tomcat_home%\common\lib\servlet-api.jar
Rather than%tomcat_home%\lib\servlet.jar (there is no such directory and class library)
3. The introduction of a third party class library must be added to the classpath or add%java_home%\lib\ under the normal loading. The tomcat5.5 (04.07.21) reference to the class library is required to add the *.jar file under%tomcat_home%\common\lib\.

There are many combinations of JSP configuration environments, which refer only to j2sdk1.5.0+tomcat5.5, but are sufficient for initial and intermediate developers to use.


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.