如何快速建立Servlet和JSP的运行环境 |
|
日期:2007-6-3 10:03:28 人气:156 [大 中 小] |
|
|
|
The recommended way to do this is to download the file bluej_tomcat_config.zip(http://www.csu.edu.au/faculty/sciagr/sis/subjects/itc357/bluej_tomcat_config.zip) and extract the files to the root directory on drive c:, making sure that you choose the option to use folder names.
If you need to manually configure BlueJ or Tomcat, you need to troubleshoot problems or you want to examine the configuration options chosen, they are explained here.
Compiling and Running Servlets on Your Local Machine
1. Run BlueJ and open the existing project in the c:\Program Files\Apache Tomcat 4.0\webapps\testing\Web-inf\classes directory
2. Create a new class and enter the code for your servlet, or use Edit-Add class from file to import an existing servlet source file.
3. Compile the servlet.
4. Start tomcat by double-clicking on startup.bat in the c:\Program Files\Apache Tomcat 4.0\bin directory. This will start Tomcat listening on port 8080 on your local machine (you don't need to be online).
5. Start up your web browser and open the URL http://localhost:8080/testing/servlet/Servletname where Servletname is the name of your servlet.
File locations and relative references within local and remote servlets
HTML files located in a directory like c:\Program Files\Apache Tomcat 4.0\webapps\testing will be accessible through a URL like http://localhost:8080/testing/filename.html
Similarly if you place an HTML file in your home directory on the SWAP server it will be assessible through a URL like http://swap.csu.edu.au:8080/username/filename.html
If you need to place an image in a page generated by a servlet, you can place it in c:\Program Files\Apache Tomcat 4.0\webapps\testing (or on the swap server in your home directory) and refer to it in the HTML as http://www.knowsky.com/imagename.jpg (eg. <IMG SRC="http://www.knowsky.com/imagename.jpg">)
If you need to link to another servlet or specify another servlet within the ACTION attribute of a form, you can simply use the servlets name. For example you could use the code <A HREF="OtherServlet"> to link to another servlet assuming that you have a file in the testing\Web-inf\classes directory called OtherServlet.class (or in your Web-inf\classes directory on the SWAP server)
If you have a static HTML page that has a link to a servlet or a form with an ACTION attribute that refers to a servlet, and the HTML page is located in the c:\Program Files\Apache Tomcat 4.0\webapps\testing directory or in your home directory on the SWAP server, use the URL servlet/ServletName to refer to the servlet (eg. ACTION="servlet/ServletName"). |
|
出处:本站原创 作者:佚名 |
|
|