1

我正在使用 dwr 发送和获取一些信息,但我收到以下错误。

service(DwrSampleTest) is not defined

当我尝试使用以下行查看文件时:

http://localhost:8080/Servlets-DWR/dwr/index.html

我得到以下异常:Access to debug pages is denied.

这是我的 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>
            <create creator="new" javascript="Dwrsample">
            <param name="class" value="com.dwrsample.servlet.DwrSampleTest"/>
        </create>
    </allow>
</dwr>

网页.xml:

<servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
        <init-param>
            <param-name>crossDomainSessionSecurity</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>debug</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>DwrsampleServlet</servlet-name>
        <servlet-class>com.dwrsample.servlet.DwrsampleServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>dwr-invoker</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>

以及我调用该方法的文件:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>DWR Sample</title>
        <script src='dwr/dwr/engine.js'></script>
        <script src='dwr/dwr/util.js'></script>
        <script src='dwr/dwr/interface/DwrSampleTest.js'></script>

        <script>
            function getName() {
                DwrSampleTest.getName({callback:setName,async:false});
            }
            function setName(strName) {
                document.getElementById("enterdwr").value = "";
                document.getElementById("enterdwr").value = strName;
            }
        </script>
    </head>
    <body>
        <h1>DWR Sample Test!</h1>

        <form method="post" name="dwrsample" id="dwrsample">
            <table>
                <tr class="lightrow">
                    <td width="1%">*</td>
                    <td width="39%">Eenter DWR</td>
                    <td width="60%"><input name="enterdwr" id="password" type="text" onblur="getName()"/></td>
                </tr>
                <tr class="lightrow">
                    <td width="1%">*</td>
                    <td width="39%">DWR Result</td>
                    <td width="60%"><input name="resultdwr" id="password" type="text" /></td>
                </tr>
            </table>
        </form>
    </body>
</html>

请帮我解决这个问题。

4

1 回答 1

2

更改 dwr.xml 文件中的条目如下

    <create creator="new" javascript="DwrSampleTest">
        <param name="class" value="com.dwrsample.servlet.DwrSampleTest"/>
    </create> 

Javascript ="DwrSampleTest" must match with the service name that you call in jsp page .

您调用了 javaclass 名称而不是调用了 javascript 类名称。

并启用调试

<init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>

将参数值更改为 true。

于 2012-07-10T07:02:46.327 回答