初学DWR,碰到的错误

zjy30015563 2012-03-31 11:54:00
我的问题是程序启动后,打开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 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 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代码

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

<%@ 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,hellocallback);
}

function hellocallback(b){
if(b){
document.getElementById("div_login").innerHTML = "登录成功";
}else{
document.getElementById("div_login").innerHTML = "登录失败";
}
}
</script>

</head>

<body>
<div id="div_login">
<form action="javascript:hellodwr()" method="post">
用户名:<input type="text" id="username" />
密码:<input type="password" id="password" />
<input type="submit" value="提交" />
</form>
</div>
</body>
</html>


求高手解答啊,google搜半天没搜到跟这有关的错误
...全文
431 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jim肖先生 2013-12-06
  • 打赏
  • 举报
回复
我也碰到这个问题了!顺序错了!
  • 打赏
  • 举报
回复
整了半天,原来是这个原因。。。
a0010012255 2012-05-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

引用 1 楼 的回复:
顺序乱了,应该是:
<script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/util.js"></script>
<script type="text/javascript" s……
[/Quote]

请问楼主 如果不按顺序来怎么设置 好像3.0以前的版本都没有顺序问题
a0010012255 2012-05-22
  • 打赏
  • 举报
回复
真的是顺序问题 这尼玛伤不起啊
zjy30015563 2012-03-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
顺序乱了,应该是:
<script type="text/javascript" src="<%=path%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=path%>……
[/Quote]

我晕啊,纠结了1个多小时
谢谢你

因为书上是这顺序,是书上错了,还是如果要这顺序的话,要设置其他的
<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" src="<%=path%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=path%>/dwr/interface/UserService.js"></script>


67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧