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

相信很多刚开始学习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.

(0)

相关推荐

  • jsp和servlet操作mysql中文乱码问题的解决办法

    首先看是从什么地方开始出现的乱码,只要统一编码,就不会出现乱码,下面以uft-8(个人认为最好)为例,详细说明: 1.如果乱码是从jsp页面出现的,jsp头部页面加上:<%@ page language="java" pageEncoding="UTF-8" %>在head标签中加上标签. 2.如果乱码是在servlet中出现的,则有两种方法:一种是在每个servlet中doget和doPost方法头部加上request.setCharacterEnco

  • JSP/Servlet应用程序优化八法

    你的J2EE应用是不是运行的很慢?它们能不能承受住不断上升的访问量?本文讲述了开发高性能.高弹性的JSP页面和Servlet的性能优化技术.其意思是建立尽可能快的并能适应数量增长的用户及其请求.在本文中,我将带领你学习已经实践和得到证实的性能调整技术,它将大大地提高你的servlet和jsp页面的性能,进而提升J2EE的性能.这些技术的部分用于开发阶段,例如,设计和编码阶段.另一部分技术则与配置相关. 技术1:在HttpServletinit()方法中缓存数据 服务器会在创建servlet实例之

  • JSP学习之Servlet用法分析

    本文讲述了JSP学习之Servlet用法.分享给大家供大家参考.具体分析如下: Servlet是使用JavaServlet应用程序设计接口编写的Java程序,源于请求/响应模式,可以接受来自客户端浏览器的Http请求,产生一个响应并返回客户端. Applet JSP JavaBean 和Servlet的区别和联系 Applet和Servlet中都没有main()方法,只有一些特定的方法,用于启动执行和退出,但是Servlet不提供用户界面,运行在服务器端,而Applet提供用户界面,运行在客户端

  • JSP与Servlet的介绍说明

    什么是Servlet和JSP 用Java开发Web应用程序时用到的技术主要有两种,即Servlet和JSP. Servlet是在服务器端执行的Java程序,一个被称为Servlet容器的程序(其实就是服务器) 负责执行Java程序.而JSP(Java Server Page)则是一个页面, 由JSP容器负责执行. Servlet和JSP两者最大的区别就是,Servlet以Java程序为主, 输出HTML代码时需要使用out.println函数,也就是说Java中内嵌HTML: 而JSP则以HTM

  • jsp引用servlet生成的验证码代码演示

    此演示代码主要包括以下三部分:1.checkCode.java:用于生成验证码2.checkCodeServler3.check.jsp 验证 下面是checkCode.java的内容: 复制代码 代码如下: //用于获取四位随机数     private char mapTable[] = {'0','1','2','3','4','5','6','7','8','9'}; //生成验证码,并返回随机生成的数字     public String getEnsure(int width, in

  • JSP、Servlet中get请求和post请求的区别总结

    在学习JavaWeb最初的开始阶段,大家都会遇到HttpServlet中的doGet和doPost方法.前两天看<Head First Servlets & JSP>看到其中讲关于Servlet中get请求和post请求的区别,现总结如下: 1:请求数据的大小不同. 因为get请求的数据是要追加到URL中,而URL的数据量一般不能超过2K,所以用get请求的方法对数据的大小有限制.而post请求方法是把数据放在消息体中,所以理论上对数据量没有限制.(但是实际操作中也不能能太大) 2:安

  • 在Jsp Servlet中页面重新定向总汇

    1. RequestDispatcher.forward() 是在服务器端起作用, 当使用forward()时,Servlet engine传递HTTP请求从当前的Servlet or JSP到另外一个Servlet,JSP 或普通HTML文件,也即你的form提交至a.jsp,在a.jsp用到了forward()重定向至b.jsp,此时form提交的所有信息在 b.jsp都可以获得,参数自动传递. 但forward()无法重定向至有frame的jsp文件,可以重定向至有frame的html文件

  • jsp和servlet的区别探讨

    答案一: 首先你先要弄懂什么是servlet,servlet是在服务器端执行的java程序,只不过它有专门的一套规则(就是我们平常所说的api):jsp说得简单点就是用另一套简单的规则写的servlet程序,它可以写java代码,还可以写html代码,JavaScript,css等等--,但是到服务器端首先会被转成servlet程序然后就按照servlet的执行顺序执行了. 答案二: 以下的是从网上找的: JSP和SERVLET到底在应用上有什么区别,很多人搞不清楚.我来胡扯几句吧.简单的说,S

  • 在jsp中用bean和servlet联合实现用户注册、登录

    声明:作者原创,版权所有.未经授权,不得转载 在jsp中用bean和servlet联合实现用户注册.登录 作者:imagebear版权:imagebear 本例需要的软件和运行环境:1.Windows2000 Server操作系统2.jdk1.43.JCreator2.5(java源码编辑调试器,吐血推荐!)4.Macromedia JRun MX5.Macromedia Dreamweaver MX(非必需)6.MySQL数据库(最好安装MySQL Control Center) 一.数据库设

  • Servlet与JSP间的两种传值情况

    Servlet与JSP 之间的传值有两种情况:JSP -> Servlet, Servlet -> JSP. 通过对象 request和 session (不考虑 application)完成传值. 一.JSP -> servlet JSP页面有3种方法向 servlet传值: form表单.URL 复制代码 代码如下: <!-- JSP page --> ... <%...... session.setAttribute("testSession"

随机推荐