免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 925 | 回复: 0
打印 上一主题 下一主题

快速建立Servlet和JSP的运行、调试和编译环境 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-09 06:23 |只看该作者 |倒序浏览
相信很多刚开始学习Servlet和JSP的朋友都有一个困扰,就是如何快速方便的建立一个Servlet和JSP的运行、调试和编译环境。

(注:文章中所提到的四个软件分别是JDK 1.3.1,BlueJ 1.2.0,Apache Tomcat 4.0和bluej_tomcat_config.zip。其中BlueJ是用来创建、编译Servlet的,而最后那个zip文件则是配置BlueJ和Tomcat的。)
BlueJ, Jakarta Tomcat and Java 2 SDK Installation
1. Install the Java 2 Software Development Kit (JDK)
It is recommended that you install JDK 1.3.1, which can be downloaded from here(http://www.csu.edu.au/faculty/sciagr/sis/subjects/itc357/j2sdk-1_3_1-win.exe), or from http://java.sun.com (unfortunately it is a 30M download so if you have a slow modem it may be better to acquire it on CD. For example, there is a CD containing JDK with many Java text books).
Install JDK to the default directory, which is c:jdk1.3.1
You may use a different version of JDK (1.2 or later) but you will need to change the Tomcat configuration files startup.bat and shutdown.bat to point to the directory location.
2. Install BlueJ (BlueJ is a basic Java editing and compilation environment that sits on top of JDK)
It is recommended that you install BlueJ 1.2.0, which can be downloaded from here(http://www.csu.edu.au/faculty/sciagr/sis/subjects/itc357/bluejsetup-120.exe) or from http://bluej.org
Install BlueJ to the default directory c:BlueJ
If you install a different version of BlueJ or place it in a different directory the configuration files provided in bluej_tomcat_config.zip will not automatically go into the correct directories and you will have to manually extract each one.
3. Install Apache Tomcat (Tomcat is a Java web application server and will allow you to test your Servlets and JSP files locally)
It is recommended that you install Apache Tomcat 4.0, which can be downloaded from here(http://www.csu.edu.au/faculty/sciagr/sis/subjects/itc357/jakarta-tomcat-4.0.4.exe) or from http://jakarta.apache.org/
Install Tomcat to the default directory c:Program FilesApache Tomcat 4.0
If you install a different version of Tomcat or place it in a different directory, you will need to configure it manually as the configuration files provided in bluej_tomcat_config.zip will not automatically go into the correct directories and various paths settings contained in them will not be correct.
4. Configure BlueJ and Tomcat to work together
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 FilesApache Tomcat 4.0webapps        estingWeb-infclasses 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 FilesApache Tomcat 4.0in 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 FilesApache Tomcat 4.0webapps        esting 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 FilesApache Tomcat 4.0webapps        esting (or on the swap server in your home directory) and refer to it in the HTML as ../imagename.jpg (eg. )
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  to link to another servlet assuming that you have a file in the testingWeb-infclasses directory called OtherServlet.class (or in your Web-infclasses 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 FilesApache Tomcat 4.0webapps        esting directory or in your home directory on the SWAP server, use the URL servlet/ServletName to refer to the servlet (eg. ACTION="servlet/ServletName").
It is recommended that you use relative references like these in your HREF, SRC and ACTION attributes so that you can easily move your pages from the local machine to the server.

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/7965/showart_55950.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP