DWR Demo

sponsored links
Dwr.jar download under the lib on
Medium in web.xml add the following code:
		<display-name>DWR Servlet</display-name>


Category deal with the preparation of background: DwrTest.java and the introduction of category DwrTestForm.java

package com.test;

import java.util.List;

import com.test.vo.DwrTestForm;

public class DwrTest {

	public DwrTestForm sayHello(List list) {
	    DwrTestForm dwrTestForm = new DwrTestForm();
	    dwrTestForm.setName(" Name  :"+(String)list.get(0));
	    dwrTestForm.setAge(" Age  :"+(String)list.get(1));
	    dwrTestForm.setSex(" Gender  :"+(String)list.get(2));
	    dwrTestForm.setAddress(" Address  :"+(String)list.get(3));
	    dwrTestForm.setPhone(" Phone  :"+(String)list.get(4));
        return dwrTestForm;


package com.test.vo;

public class DwrTestForm
    String name;
    String age;
    String sex;
    String address;
    String phone;
    public String getName()
        return name;
    public void setName(String name)
        this.name = name;
    public String getAge()
        return age;
    public void setAge(String age)
        this.age = age;
    public String getSex()
        return sex;
    public void setSex(String sex)
        this.sex = sex;
    public String getAddress()
        return address;
    public void setAddress(String address)
        this.address = address;
    public String getPhone()
        return phone;
    public void setPhone(String phone)
        this.phone = phone;


Add dwr.xml with the preparation of a web.xml directory:
    "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"

    <create creator="new" javascript="Demo">
      <param name="class" value="com.test.DwrTest"/>
      <include   method="sayHello" />
    <convert converter="bean" match="com.test.vo.DwrTestForm"> 
			<param name="include" value="name,age,sex,address,phone"/>

Prepare jsp page
<%@ page language="java" contentType="text/html; charset=UTF-8"
String contextPath = request.getContextPath();
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript"
    src="../dwr/interface/Demo.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 send()
        var list = new Array();
        list[0] = document.getElementById("text1").value;
        list[1] = document.getElementById("text2").value;
        list[2] = document.getElementById("text3").value;
        list[3] = document.getElementById("text4").value;
        list[4] = document.getElementById("text5").value;
        Demo.sayHello(list, callBack);

    function callBack(backValue)
        document.getElementById("result").innerHTML = backValue.name + " "
                + backValue.age + " " + backValue.sex + " " + backValue.address
                + " " + backValue.phone;

  Name:<div><input type="text"/></div>
  Age:<div><input type="text"/></div>
  Sex:<div><input type="text"/></div>
  Address:<div><input type="text"/></div>
  Phone:<div><input type="text"/></div>
  <input  value="Send" type="button"/>

This can be a java call js

If the start times
java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory abnormal
Will have to add in the lib in the package commons-loggin.jar
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of DWR Demo

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • First Hibernate Example

    Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries