首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

DWR小的范例

2012-10-25 
DWR小的实例package com.bwrimport java.io.Filepublic class service {??? public String sayHello(Str

DWR小的实例

package com.bwr;

import java.io.File;

public class service {
??? public String sayHello(String yourName) {? ???
??? ??? return "Hello World " + yourName;
??? ??? }

}

}

*********************

web.xml

*********************

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
??? <display-name>Application</display-name>
??? <description>
??? ??? A application for test.
</description>
??? <servlet>
??? ??? <servlet-name>dwr-invoker</servlet-name>
??? ??? <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
??? ??? <init-param>
??? ??? ??? <param-name>debug</param-name>
??? ??? ??? <param-value>true</param-value>
??? ??? </init-param>
??? ??? <init-param>
??? ??? ??? <param-name>classes</param-name>
??? ??? ??? <param-value>java.lang.Object</param-value>
??? ??? </init-param>
??? </servlet>
??? <servlet-mapping>
??? ??? <servlet-name>dwr-invoker</servlet-name>
??? ??? <url-pattern>/dwr/*</url-pattern>
??? </servlet-mapping>
</web-app>

***************************

dwr.xml

***************************

??? <allow>
??? ??? <create creator="new" javascript="service">
??? ??? ??? <param name="class" value="com.bwr.service" />
??? ??? </create>
??? </allow>

***************************

Jsp files

***************************

<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>My JSP 'first_dwr.jsp' starting page</title>
<script type='text/javascript' src='/dwr/util.js'></script>
<script type='text/javascript' src='/dwr/engine.js'></script>
<script type='text/javascript' src='/dwr/interface/service.js'> </script>
<script type="text/javascript">
function firstDwr()
{ ???
??? service.sayHello("Jorwen",callBackHello);
??? }
function callBackHello(data)
{?
??? alert(data);
}
</script>
</head>
?
<body>
<input type="button" name="button" value="测试" onclick="firstDwr()">
</body>
</html>

*****************************************

热点排行