1、打开MyEclipse,新建一个Web Project项目,名为“dojo_test”。如图:

 

 

2、在WebRoot目录下新建一个scripts目录,用于存放javascript代码。

3、下载最新的dojo(下载地址:http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1.zip)。

4、将下载的dojo解压到scripts目录下。如图:

 

 

5、新建一个jsp页面,名为“helloworld.jsp”。

6、在helloworld.jsp中编写如下代码:

 

 
  
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
  2. <%  
  3.     String path = request.getContextPath();  
  4.     String basePath = request.getScheme() + "://"  
  5.             + request.getServerName() + ":" + request.getServerPort()  
  6.             + path + "/";  
  7. %> 
  8.  
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
  10. <html> 
  11.     <head> 
  12.         <base href="<%=basePath%>"> 
  13.  
  14.         <title>Dojo, Hello world!</title> 
  15.  
  16.         <meta http-equiv="pragma" content="no-cache"> 
  17.         <meta http-equiv="cache-control" content="no-cache"> 
  18.         <meta http-equiv="expires" content="0"> 
  19.         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
  20.         <meta http-equiv="description" content="This is my page"> 
  21.         <!-- 引入dojo.js --> 
  22.         <script type="text/javascript" src="scripts/dojo-release-1.8.1/dojo/dojo.js"></script> 
  23.         <script type="text/javascript"> 
  24.             dojo.addOnLoad(function () {  
  25.                 dojo.create("div", { innerHTML: "这是一个由Dojo加载的【Hello world!】" }, dojo.body());  
  26.             });  
  27.         </script> 
  28.     </head> 
  29.  
  30.     <body> 
  31.         <h1>Dojo的第一个示例</h1> 
  32.     </body> 
  33. </html> 

7、启动tomcat服务器,输入“http://localhost:8080/dojo_test/helloworld.jsp”。可见如图所示的效果: