Tomcat configuration servlet experience talk-Novice must see (recommended)
Author: Unknown article source: www.jspcn.net
Release date: January 19, 2005 views: 11,855 Times
The internet to find their own, there is no one more easy and specific configuration instructions, tease, try to go, just do the Tomcat's servlet configuration and running problems (in fact, is how to run the path problem), I was a rookie, see everyone was tossing, the hearts of empathy, write down this article, if there is any mistake, Please respect and a lot of advice!!
(!!!! Attention:!!!!! The configuration instructions are according to my own directory path to explain, we please according to their specific path to change is, as to what the details of the role of the file is not said, they can search for articles, a lot of is "I also do not know, in short, can run is, Xi Hee")
I Tomcat installation directory: E:tomcat 4.1
Java installation directory: e:j2sdk1.4.2
A
(1) First needless to say, of course, download pull (nonsense, hehe)
Tomcat.exe Download: Http://www.apache.org/dist/jakarta/tomcat-4/v4.1.31/bin/jakarta-tomcat-4.1.31.exe
JDK Download: http://java.sun.com/j2se/1.4.2/download.html
(2) Install Jdk,tomcat separately
My environment is configured as follows:
First, add e:j2sdk1.4.2 in under Path
Second, the following is a new system variable
1) classpath Add the following (remember the first "point" and "semicolon")
.; E:j2sdk1.4.2lib; E:j2sdk1.4.2libdt.jar; E:j2sdk1.4.2lib Ools.jar; E:tomcat 4.1commonlibservlet.jar
2) java_home Add (your JAVA installation directory) e:j2sdk1.4.2
3) tomcat_home Add (your TOMCAT installation directory) E:tomcat 4.1
OK, the basic environment variable is configured here, and then try to open the Startup.bat command in the Tomcat in directory, and then enter http://localhost:8080 in the browser's address bar. If you see Tomcat's big cat, that means you've successfully installed it.
Two
After doing the above steps, you will need to make some changes to run your personal servlet, and modify two files (Web.xml, server.xml) separately.
(1) First of all to do a good job directory problem:
I created a myservlets my working directory in my E:tomcat 4.1webapps directory, followed by myservlets
Web-inf directory, Web-inf directory to create classes directory, this classes directory is used to store your compiled. Class (that is, the Servelt file you want to run)
My personal full path is: E:tomcat 4.1webappsmyservletsweb-infclasses
(2) then write a helloworld.java and compile the code as follows:
Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doget (HttpServletRequest request, httpservletresponse response)
Throws IOException, Servletexception
{
Response.setcontenttype ("text/html");
PrintWriter out = Response.getwriter ();
Out.println ("Out.println ("Out.println ("<title>hello world!</title>");
Out.println ("Out.println ("<body>");
Out.println ("Out.println ("</body>");
Out.println ("}
}
After compiling, copy the files to the E:tomcat 4.1webappsmyservletsweb-infclasses directory that you just created.
(3) (to modify the Web.xml file)
Copy the Web.xml file in the E:tomcat 4.1conf directory to the newly created E:tomcat 4.1webappsmyservletsweb-inf directory, open with Notepad, and add the contents:
(!!!!! It is absolutely important to note that the added content must be placed between </description> and </web-app>, not directly after the </web-app> add, I personally because directly in </web-app> After adding, and engaged for a long time, the last success is here, do not know whether to laugh or cry good xxxx, is so little things into the overall situation, so everyone should pay attention to the details of things at ordinary times.
Add all the good code as follows: (The HelloWorld of which is just compiled. class file name, everyone changes according to their own)
<?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>welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
(4) (Modify Server.xml file)
Use Notepad to open the Server.xml file under E:tomcat 4.1conf
and find a piece of content:
<context path= "/examples" docbase= "examples" debug= "0"
Reloadable= "true" crosscontext= "true" >
Modified as follows:
<context path= "/myservlets" docbase= "myservlets" debug= "0"
Reloadable= "true" crosscontext= "true" >
Where/myservlets refers to the newly created working directory (that is, E:tomcat 4.1webappsmyServlets)
Save the changes.
Three
Okay, all right, then of course, run Servelt, start Tomcat (that is, Startup.bat), open the browser, and enter http://localhost:8080 followed by the working directory name myservlets Plus Servelt file name (that is, compiled. class file)
Full path is: Http://localhost:8080/myServlet/HelloWorld
Well, see Hello World now.
All done, bye.
[Essence] The configuration of the JSP, servlet, and JavaBean environment under Tomcat
Http://www.chinaunix.net Author: Echoguo published on: 2006-03-08 21:58:48
"Comment" "View original" "Java Discussion area" "Close"
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; (.;;; Must not be less because it represents the current path)
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 are 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: <%=new java.util.Date ()%>;
</center>;</body>;6. Restart Tomcat
7. Open the browser, enter http://localhost:8080/myapp/index.jsp to see the current time, the description is successful.
Step Fourth: Build Your own servlet:
1. Create a new servlet program with your most familiar editor (the recommended syntax-checked Java IDE), with the file named Test.java, which reads 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 ("Out.flush ();
}
}
2. Compile
Place the Test.java under C:\Test and compile with the following command:
C:\test>;javac Test.java
Then a compiled servlet file is generated under C:\Test: Test.class
3. Cut the structure Test\test.class to%catalina_home%\webapps\myapp\web-inf\classes, that is, cut the Test directory to the classes directory, if the classes directory does not exist, Just create a new one. Now, there's a Test\test.class file directory structure under Webapps\myapp\web-inf\classes.
4. Modify Webapps\myapp\web-inf\web.xml, add servlet and servlet-mapping
The edited Web.xml is as follows, red for added content:
<?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" >;
<display-name>; My Web application</display-name>;
<description>;
A Application for test.
</description>;
<servlet>;
<servlet-name>; test</servlet-name>;
<display-name>; test</display-name>;
<description>; A Test servlet</description>;
<servlet-class>;test. test</servlet-class>;
</servlet>;
<servlet-mapping>;
<servlet-name>; test</servlet-name>;
<url-pattern>;/Test</url-pattern>;
</servlet-mapping>;
</web-app>;
The servlet section of this passage declares the servlet you want to invoke, while servlet-mapping "maps" the declared servlet to the address/test
5. OK, start Tomcat, start the browser, enter Http://localhost:8080/myapp/Test if you see the output this is a servlet Test. The servlet that wrote the note was successful.
Note: The Web.xml is modified and the new class is added to restart Tomcat
Step Fourth: Build Your own bean:
1. Create a new Java program with your most familiar editor (the recommended syntax-checked Java IDE), with the file named Testbean.java, which reads 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. Compile
Place the Testbean.java under C:\Test and compile with the following command:
C:\test>;javac Testbean.java
Then a compiled bean file is generated under C:\Test: Testbean.class
3. Cut the Testbean.class file to%catalina_home%\webapps\myapp\web-inf\classes\test,
4. Create a new testbean.jsp file with the following contents:
<%@ page import= "test. Testbean "%>;
<%
Testbean testbean=new Testbean ("This is a test Java bean.");
%>;
Java Bean name is: <%=testbean.getname ()%>;
</center>;</body>;5. OK, restart Tomcat, start the browser, and enter http://localhost:8080/myapp/TestBean.jsp if you see the output Java Bean name Is:this is a test Java bean. Written on the note b The EAN succeeded.
This completes the configuration of the JSP, Servlet, and JavaBean under Tomcat. The next thing to do is to read more books, reading other people's good code, and more hands-on writing code to enhance their ability to develop in this area.
Talking about configuring Tomcat in Eclipse
Http://developer.51cto.com/art/200906/127381.htm
about configuring Tomcat in Eclipse 2009-06-05 14:59 51cto blog I want to comment (7) font size: T | T
This article outlines some of the experiences of configuring Tomcat in Eclipse.
AD:
In order to test struts2 in Eclipse, it was found that eclipse on its own machine did not integrate Tomcat, looking for a long time on the internet, not the plugin did not download the address, that is, there are a lot of attention or version issues.
As a result, the plug-in to the tomcatforeclipse of their own online download a direct, according to the instructions provided in a single match.
So many configuration articles on the Web, alas, do not say anything.
Take a look at my configuration steps.
Installation of 1,eclipse. This is downloaded from Eclipse's official website. Do not teach it, download the exe file after the installation. My version is, the Eclipse SDK
version:3.4.2
Build id:m20090211-1700
2, download a tomcat, downloaded from the official Apache website, I am under, 6.x version, file name: Apache-tomcat-6.0.20.exe
Address http://tomcat.apache.org/download-60.cgi, download the Windows version, download exe file after a slide installation, installation content part of the choice of all, all the other default configuration, the middle of the admin password, enter your own set the password can be.
Start after installation, rely on, can not start. Originally installed, the machine is used Jre6,tomcat is also jre6, as if not supported, that good download a jdk5, from Sun's official website download,
I am under the Jdk-1_5_0_19-nb-6_5_1-windows-ml.exe, integrated Netbean version, downloaded after the default installation.
installed, uninstall tomcat, reinstall, JRE part made into jre1.5, after installation, service start Tomcat, browser input, Http://localhost:8080/,ok, the page out of normal expression.
3, download Tomcat's plugin for Eclipse.
Download Address: http://www.eclipsetotale.com/tomcatPlugin.html
This page also, installation instructions, English good can see for themselves.
This is my tomcatpluginv321.zip.
After downloading, unpack. The extracted files are placed in Eclipse's plug directory, as shown in the figure.
Then start eclipse and see three icons, as shown in
This time point three icons, appear prompts to tell you not to.
You also need to configure the Tomcat version, and Tomcat's home, reference map,
Once configured, apply the button to press, close, and then stop Tomcat services from window services.
Back to Eclipse's page, click on the three icons, OK, the console window below is reflected.
Then open the browser, Http://localhost:8080/ok, and Tomcat starts.
Finally, the summary, very simple, configuration. I do it quickly, according to those tutorials on the Internet is easy to confuse people, but, say, my article is also a reference to some of the online tutorials.
Want to be able to provide help to the configured person.