1、打开MyEclipse,新建一个Web Project项目,名为“dojo_test”。如图:
650) this.width=650;" border="0" alt="" src="http://img.558idc.com/uploadfile/allimg/210615/22235R623-0.png" d="4730635" s="a6a_1ce" t="png">
2、在WebRoot目录下新建一个scripts目录,用于存放javascript代码。
650) this.width=650;" border="0" alt="" src="http://img.558idc.com/uploadfile/allimg/210615/22235R623-0.png" d="4730636" s="6a3_12f" t="png">
3、下载最新的dojo(下载地址:http://download.dojotoolkit.org/release-1.8.1/dojo-release-1.8.1.zip)。
4、将下载的dojo解压到scripts目录下。如图:
650) this.width=650;" border="0" alt="" src="http://img.558idc.com/uploadfile/allimg/210615/22235R623-0.png" d="4730637" s="1f0_50a" t="png">
5、新建一个jsp页面,名为“helloworld.jsp”。
6、在helloworld.jsp中编写如下代码:
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme() + "://"
- + request.getServerName() + ":" + request.getServerPort()
- + path + "/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>Dojo, Hello world!</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <!-- 引入dojo.js -->
- <script type="text/javascript" src="scripts/dojo-release-1.8.1/dojo/dojo.js"></script>
- <script type="text/javascript">
- dojo.addOnLoad(function () {
- dojo.create("div", { innerHTML: "这是一个由Dojo加载的【Hello world!】" }, dojo.body());
- });
- </script>
- </head>
- <body>
- <h1>Dojo的第一个示例</h1>
- </body>
- </html>
7、启动tomcat服务器,输入“http://localhost:8080/dojo_test/helloworld.jsp”。可见如图所示的效果:
650) this.width=650;" border="0" alt="" src="http://img.558idc.com/uploadfile/allimg/210615/22235R623-0.png" d="4730638" s="a53_bba" t="png">