动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Jsp → 阅读文章

 快速建立Servlet和JSP的运行、调试和编译环境

作者来源: 
阅读 1685 人次 , 2006-3-29 4:21:00 

相信很多刚开始学习servlet和jsp的朋友都有一个困扰,就是如何快速方便的建立一个servlet和jsp的运行、调试和编译环境。本人现在正在国外攻读mit(master of information technology),现在选修的这一科是wbis(web based information systems),其包含了许多种技术,如java,perl,cgi,servlet,asp,java script,jsp,oo,uml等等。下面的这篇文章是学校所提供的相关软件的下载地址、安装方法以及相关说明,其中的所需的软件(学校已经给我们提供了cd)我已经全部安装并测试过。这里,我极力推荐给大家,因为整个安装过程非常的简单,只要按照下面文章中的方法一步一步做,100%可以成功,相信会给你带来帮助。虽然文章是全英文的,但很简单,相信大家都能明白。如果有什么问题,希望大家能提出来我们一起讨论。

(注:文章中所提到的四个软件分别是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 files\apache 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 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 ../imagename.jpg (eg. <img src="../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").

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.

 本文Tags编译  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:JSP学习心得
· 下一篇:JSP迅速入门
· Servlet和JSP概述
· 客户端Cookie中文编程
· JSP调用JavaBean在网页上动态生成柱状图
· 如何直接在浏览器内运行SQL命令
· Java传说之风云再起


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077