日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

dwr入門代碼一

系統 2328 0

WEB-INF目錄下創建一個dwr.xml文件
dwr.xml 配置代碼:
Xml代碼
<?xml version="1.0" encoding="UTF-8"?>????
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" " http://getahead.org/dwr//dwr20.dtd ">????
<dwr>????
<!-- without allow, DWR isn't allowed to do anything -->????
<allow>????????
<!--creator設定為new,表示使用Hello的無參數建構子來生成物件,javascript設定為Hello,表示客戶端JavaScript程式可以使用Hello來呼叫對應的onlyfun.caterpillar.Hello物件-->????
????<create creator="new" javascript="Hello" scope="application">??????????
????????<param name="class" value="com.xzj.service.HelloWorldService"/>??????????
????</create>????
</allow>????
</dwr>??
web.xml中的配置如下:
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 " version="2.4"
xsi:schemaLocation=" http://java.sun.com/xml/ns/j2ee ?? <A href=" http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "
target=_blank>http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd</A>">????
??<!-- DWR配置開始 -->????
?? <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>????????
??<!-- DWR配置結束 -->????
????????
??<welcome-file-list>????
????<welcome-file>index.jsp</welcome-file>????
??</welcome-file-list>????
</web-app>????

然后我們在src目錄下創建一個com.xzj.service包在次包中創建一個類名為:HelloWorldService
在這個包中寫兩個方法
在這個包中寫兩個方法
代碼如下:
Java代碼
package com.xzj.service;??????
????
public class HelloWorldService {??????
????private static String msg="請輸入姓名!";??????
??????????
????public String helloWorld(){??????
????????return "Hello DWR World!";??????
????}??????
??????????
????public String hello(String name){
????????
???? if("".equals(name)||null==name){
????????return msg;
????}
???? if(!"".equals(name)||null==name){
??????????msg="Hello"+name+" 先生";
???? }
??????return msg;
????}
}????

然后我們回到前臺index.jsp頁面中 代碼如下:
Java代碼
<%@ page language="java"??pageEncoding="UTF-8"%>??????
<html>??????
??<head>??????
????<title>DWR 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">??
<!--dwr/interface/Hello.js是由DWRServlet根據dwr.xml中的設定生成的,engine.js負責客戶端伺服端溝通,util.js是一些好用的JavaScript程式,可以讓您少寫很多JavaScript。-->????
???????? <!--下面三個必須要第一個和你dwr.xml配置的javascript="Hello"一樣-->??????
????<script type="text/javascript" src='dwr/interface/Hello.js'></script>??????
  ?????? <script type="text/javascript" src='dwr/engine.js'></script>??????
  ?????? <script type="text/javascript" src='dwr/util.js'></script>??????
????<script type="text/javascript">??????
????????function helloWorld(){??????
????????????Hello.helloWorld(showMessage);??????
????????????function showMessage(msg){??????
????????????????alert(msg);??????
????????????}??????
????????}??????
??????????????
????????function hello(){??
??????????// var name = $('txtName').value;
??????????//Hello.hello(name,showMessage());????
????????????Hello.hello(txtName.value,showMessage);??????
????????????function showMessage(msg){??????
????????????????alert(msg);??????
????????????}??????
????????}??????
????</script>??????
??</head>??????
??<body>??????
????<center>??????
????????<input type="button" name="btnHello" value="HelloWord" onclick="helloWorld()"/>??????
????????<br><br><br><br>??????
????????Please Enter You Name:<input type="text" name="name" id="txtName"/>??????
????????<input type="button" name="btnHello" value="HelloWord" onclick="hello()"/>??????
????</center>??????
??</body>??????
</html>????
另外版本需要的是5.5的,6.0的配置變了

dwr入門代碼一


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 平山县| 昆明市| 尤溪县| 天长市| 布尔津县| 临朐县| 崇明县| 沙湾县| 葵青区| 宁波市| 调兵山市| 林芝县| 连城县| 科尔| 宜兴市| 绥江县| 呈贡县| 错那县| 济南市| 高陵县| 凤城市| 北流市| 新竹市| 武威市| 杭州市| 大洼县| 新河县| 克什克腾旗| 潞西市| 朝阳区| 怀来县| 梨树县| 宜兰县| 桃江县| 从化市| 铜鼓县| 高尔夫| 唐河县| 兴和县| 米泉市| 龙南县|