dwr 写的小程序,配置
生活随笔
收集整理的這篇文章主要介紹了
dwr 写的小程序,配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一、在web.xml里面有如下配置:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
第二,在web.xml同目錄下添加一個dwr.xml文件:javascript 唯一,作為jsp頁面的引用
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="Hello" >
<param name="class" value="com.hoo.entity.Message"/>
</create>
</allow>
</dwr>
第三,寫一個java類
package com.hoo.entity;public class Message {
public String hello(String name) {
return "這是" + name + "的第一個dwr";
}
}
第四,寫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>Chat</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/engine.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/util.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/interface/Hello.js"></script>
<%--<script type="text/javascript" src="chat.js"> </script>
--%><script type="text/javascript">
function hello() {
var user = document.getElementById("user").value;
//var user = $('user').value;
Hello.hello(user, callback);
}
function callback(msg) {
DWRUtil.setValue('result', msg);
}
</script>
</head>
<body>
<input id="user" type="text" />
<input type='button' value='你好' onclick='hello();' />
<jsp:useBean id="abc" class="com.hoo.entity.Message"></jsp:useBean>
<jsp:getProperty property="str" name="abc"/>
<div id="result"></div>
</body>
</html>
要記得在項目中添加的包有:commons-logging.jar? dwr.jar?? log4j.jar
總結
以上是生活随笔為你收集整理的dwr 写的小程序,配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET3.5 企业级项目开发 -
- 下一篇: 简明 jieba 中文分词教程