`
高级java工程师
  • 浏览: 409031 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

第五章

    博客分类:
  • ajax
阅读更多
关键字: dwr 学习笔记<三>demo
首先下载dwr.jar

2个配置文件

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

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" version="2.4"

   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

      

    <!-- Struts Action Mapping-->

<servlet>

  <servlet-name>action</servlet-name>

  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

  <init-param>

   <param-name>config</param-name>

   <param-value>

    /WEB-INF/struts-config.xml

   </param-value>

  </init-param>

  <load-on-startup>2</load-on-startup>

</servlet>

<!-- 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>



<servlet-mapping>

  <servlet-name>action</servlet-name>

  <url-pattern>*.do</url-pattern>

</servlet-mapping>

  

   <welcome-file-list>

    <welcome-file>index.html</welcome-file>

   </welcome-file-list>

</web-app>

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

dwr.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>

<allow>

  <!-- DEMO class -->

  <create creator="new" javascript="JDate">

   <param name="class" value="java.util.Date" />

  </create>

  <create creator="new" javascript="Test">

   <param name="class" value="com.cosmic.conn.Test" />

   <include method="add"/>

   <include method="getList"/>

  </create>

</allow>

</dwr>

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

jsp

<%@ page language="java" contentType="text/html; charset=shift-jis"

    pageEncoding="windows-31j"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">

<title>Insert title here</title>

    <script type='text/javascript' src='dwr/interface/Test.js'></script>

<script type='text/javascript' src='dwr/engine.js'></script>

<script type='text/javascript' src='dwr/util.js'></script>

</head>

<script type="text/javascript" language="javascript">



      function add()

  {

     //var id=document.getElementById("userId").value;

   Test.getList(callBackAdd);

   //alert(id);

  }





  function callBackAdd(data){

  alert(data);

for(var attr in data){

  alert(attr + "\t" + data[attr]);



}

   //reCheckId=id;

  //alert(c);

   //userIdMsg(id);

  }

    </SCRIPT>

<body>

<html:form styleId="mainform" action="InsertAction" method="post">



<td width="200" align="center">

       

        <html:button property="aaa" value="bbbbbb" onclick="add();"></html:button>

        

</td>



         

</html:form>

</body>

</html>

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

Test.java

package com.cosmic.conn;

import java.util.*;

public class Test {

public int add(int a, int b)

{

  return a+b;

}



public List getList() {



  List  list = new ArrayList();

  for(int i=0;i<5;i++)

  {

   list.add(i);

   //list.add("liu"+i);

     }

    return list;

  }

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics