Jsp+javabean+servlet Development Environment Configuration Guide

Source: Internet
Author: User
Tags config variables reference variable xmlns root directory tomcat
Js|servlet *************************************
This paste from the Internet search, is my beginner JSP found the best one of the configuration guide. The original author has not been able to determine, but here is a tiny token of thanks. At the outset, I walked through the Tomcat English document still can't find the servlet installation configuration method (I level limited), then see this post suddenly enlightened. Worth recommending.
*************************************

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

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 has 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\.

This post is only for reference, JSP configuration environment has many combinations, here only mentioned j2sdk1.5.0+tomcat5.5, but the foot has been for the beginning, intermediate developers to use! The shortcomings of the post please do not hesitate to enlighten us, not grateful!



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.