衫裤跑路 2013-04-11 07:05 采纳率: 50%
浏览 33

DWR示例不起作用

I copied the example from a website and it is not working, can anyone tell me what is the reason. I am not getting any exceptions or errors in the console log of tomcat.

below are my files dwrtest.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>DIRECT WEB REMOTING (DWR) TEST APPLICATION</title>

        <base href="${pageContext.request.contextPath}">

        <!-- You have to include these two JavaScript files from DWR -->
        <script type='text/javascript' src='dwr/engine.js'></script>
        <script type='text/javascript' src='dwr/util.js'></script>

        <!-- This JavaScript file is generated specifically for your application -->
        <script type='text/javascript' src='dwr/interface/Calculator.js'></script>

        <script type='text/javascript'>

        function dwrAjaxRequest() {
            var num1 = DWRUtil.getValue("num1");
            var num2 = DWRUtil.getValue("num2");
            Calculator.addNumbers(num1,num2,dwrAjaxResponse);
        }

        function dwrAjaxResponse(result) {
            DWRUtil.setValue("resultText",result);
        }
      </script>
</head>
    <body>
        <h2>DWR SAMPLE APPLICATION</h2>
        <b>Number 1 : </b><input type="text" value="5" name="num1"/><br>
        <b>Number 2 : </b><input type="text" value="6" name="num2"/><br>
        <b>Result : </b><input type="text" value="" name="resultText"/><br>
        <input type="button" value="Add" name="go"  onClick="dwrAjaxRequest();"/>
    </body>
</html>

Below is the dwr.xml file copied in WEB-INF folder

<?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>
        <create creator="new" javascript="Calculator">
            <param name="class" value="com.example.dwr.Calculator"/>
            <include method="addNumbers"/>
        </create>
    </allow>
</dwr>

Below is the web.xml under WEB-INF folder

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

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

Below is my Calculator.java class which is in package structure com.example.dwr

package com.example.dwr;

public class Calculator {
      public int addNumbers(int a , int b) {
        return (a + b);
      }

}

I am new to DWR please let me know what is wrong with this example ** when i click the add button nothing happens, actually result should come in the result text box**

  • 写回答

1条回答 默认 最新

  • weixin_33719619 2013-10-14 10:22
    关注

    try to expose whole class rather than a particular method,you can download a working example here

    <?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>
    <create creator="new" javascript="forms">  
    <param name="class" value="com.stringpool.demo.Status"/>  
    </create> 
    </allow>
    </dwr>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题