Source: Introduction to configuration in various forums: scum updated: 2008/08/31
----------------1. Development Environment configuration ----------------
1.1 download j2sdk and tomcat:J2sdk:
Http://java.sun.com/j2se/ Download Windows offline installation.Tomcat:
Http://jakarta.apache.org/site/downloads/1.2 install and configure j2sdk and Tomcat (default installation configuration ).1.3 after j2sdk is installed, add the following system variables to the system variables:Java_home = C:/j2sdk1.5.0 (actual installation path) classpath = .; % java_home %/lib/DT. jar; % java_home %/lib/tools. jar ;(.; is the current path) Path = % java_home %/bin (path is the environment variable)
1.4 write a simple JavaProgramTest whether JDK is successfully installed:Public class test {public static void main (string ARGs []) {system. out. println ("this is a test Java app. ") ;}} Save the preceding content as test. java. compile this program in the Command Prompt window: javac test. if Java test is compiled and runs normally, this is a test Java app will be output on the screen.
1.5 after Tomcat is installed, add the following system variables:Catalina_home = C:/tomcat (actual installation path) catalina_base = C:/tomcat modify the environment variable classpath: classpath = .; % java_home %/lib/DT. jar; % java_home %/lib/tools. jar; % catalina_home %/common/lib/servlet. jar;
1.6 start Tomcat and accessHttp: // localhost: 8080. The Tomcat welcome page is displayed. The installation is successful!----------------------2. Create a JSP site----------------------2.1 create a directory named MyApp in % tomcat_home %/webapps.2.2 create a directory WEB-INF (case sensitive) under MyApp ).2.3 create a file web. xml in the WEB-INF with the following content:<? XML version = "1.0" encoding = "ISO-8859-1"?> <Web-app http://java.sun.com/xml/ns/javaee "> http://java.sun.com/xml/ns/javaee" xmlns: http://www.w3.org/2001/XMLSchema-instance "> http://www.w3.org/2001/XMLSchema-instance" xsi: schemalhttp: // java.sun.com/xml/ns/javaee "> http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "Version = "2.5"> <display-Name> first JSP test </display-Name> <description> first JSP test </description> </Web-app>
2.4 create a file index. jsp in MyApp with the following content:<HTML> <body> <center> now time is: <% = new java. util. Date () %> </center> </body>
2.5 restart Tomcat and openHTTP: /localhost: 8080/MyApp/index. jspThe current time of the page output is displayed. The configuration is successful!--------------------3. Create a Servlet--------------------3.1 create a Servlet Source file named test. Java with the following content: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 ("<HTML> <body>
3.2 compile servlet: After javac test. Java is compiled successfully, the test. Class file will be generated.
3.3 deploy servlet:In % tomcat_home %/webapps/MyApp/WEB-INF/new directory classes/test, copy test. Class to this directory. Note: directory names must follow Java package deployment principles, case sensitive.
3.4 modify % tomcat_home %/webapps/MyApp/WEB-INF/Web. XML, add servlet ing, insert the following content into the <web-app> section:<Servlet> <servlet-Name> test </servlet-Name> <display-Name> test </display-Name> <description> first test servlet </description> <servlet- class> test. test </servlet-class> </servlet> <servlet-mapping> <servlet-Name> test </servlet-Name> <URL-pattern>/test </url-Pattern> </servlet-mapping> note: <servlet> the section declares the servlet to be called. the <servlet-mapping> section maps the declared servlet to the address/test (similar to the WebService portal ).
3.5 restart Tomcat and openHTTP: /localhost: 8080/MyApp/testThe page outputs this is a servlet test. The servlet is successfully deployed! Note: After modifying web. XML and the newly deployed servlet, you must restart tomcat.
---------------------4. Create a JavaBean---------------------4.1 create a Java source file named testbean. Java with the following content:Package test; public class testbean {private string name = "scumix"; 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 ;}}
4.2 compile Bean:After javac testbean. Java is compiled successfully, the file testbean. class will be generated.
4.3 cut the testbean. Class file to % atat_home %/webapps/MyApp/WEB-INF/classes/test4.4 create a new testbean. jsp file with the following content: <
% @ PageImport = "test. testbean" %> <HTML> <body> <center> <% testbean = new testbean ("test JavaBean! "); %> JavaBean name is: <% = testbean. getname () %> </center> </body>
4.5 restart Tomcat and openHTTP: /localhost: 8080/MyApp/testbean. jsp, Output JavaBean name is: Test JavaBean !, Javabean is successfully deployed! So far, the basic configuration of Tomcat-based JSP, Servlet, and JavaBean is complete.
Note:All content has been tested. The environment is as follows: j2sdk 1.6.0 Update 10 Apache Tomcat 6.0.16
Appendix:After testing, the project created by netbeans can be released. war package. copy the war file to % atat_home %/webapp/to complete the deployment (eclipse should also be available ). old tomcat versions will be decompressed when the application is accessed for the first time. war file. Versions later than 6.0 will regularly check the webapp directory when there is a new one. after the war file is published to this directory, it is automatically pre-decompressed to speed up the first access.
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.