日期:2014-05-19  浏览次数:20725 次

初学DWR,碰到的错误
我的问题是程序启动后,打开index.jsp firefox就报错

'You must include DWR engine before including this file'

if (typeof dwr == 'undefined' || dwr.engine == undefined) throw new Error('You must include DWR engine before including this file');


web.xml配置
XML code

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>dwr_invoker</servlet-name>
        <servlet-class>org.directwebremoting.servlet.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>



dwr.xml配置
XML code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" 
                "http://getahead.org/dwr/dwr30.dtd">
<dwr>
    <allow>
        <create creator="new" javascript="UserService">
            <param name="class" value="com.accp.service.UserService"></param>
            <include method="login"/>
        </create>
    </allow>
</dwr>



java代码
Java code

package com.accp.service;

public class UserService {
    public boolean login(String username,String password){
        if(username.equals("zjy") && password.equals("300")){
            return true;
        }
        return false;
    }
}



index.jsp代码
HTML code

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>DWR page</title>

    <script type="text/javascript" src="<%=path%>/dwr/interface/UserService.js"></script>
    <script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
    <script type="text/javascript" src="<%=path%>/dwr/util.js"></script>
    
    <script type="text/javascript">
        function hellodwr(){
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            alert(password);
            UserService.login(username,password,hellocallbac