spring+dwr的配置问题
我按照一篇整合文章的流程做下来,把dwr加到以前的一个ssh项目中,浏览器提示错误:DWRUser未定义,现把各个配置文件的代码贴出来:
web.xml:
...
<!--配置DWR拦截器-->
<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>
...
dwr.xml 该文件和web.xml放在WEB-INF下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="spring" javascript="DWRUser">
<param name="beanName" value="userService"/>
</create>
</allow>
</dwr>
其中userService是spring中的beanid,DWRUser是调用的js对象.
applicationContext.xml
...
<bean id="userService" class="com.mobie.service.impl.UserServiceImpl" singleton="false">
<property name="userdao">
<ref bean="UserDAO" />
</property>
</bean>
...
jsp页面:
<%@ page contentType="text/html;charset=GBK" language="java"%>
<%
//Returns the portion of the request URI that indicates the context of the request.
//The context path always comes first in a request URI.
//The path starts with a "/" character but does not end with a "/" character.
//For servlets in the default (root) context, this method returns "".
//The container does not decode this string.
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<HEAD>
<BASE href=" <%=basePath%> "/>
<META http-equiv="Content-Type" content="text/html;charset=gb2312">
<TITLE> 用户登陆 </TITLE>
<LINK href="css/style.css" rel="stylesheet" type="text/css">
<script type='text/javascript' src='/dwr/interface/DWRUser.js'> </script>
<script type='text/javascript' src='/dwr/engine.js'>
</script>
<script type='text/javascript' src='/dwr/util.js'>
</script>
<STYLE type="text/css">
body{
text-align:center;
}
</STYLE>
<script type='text/javascript'>
function regUserChked(form){
var _form = form;
var username=_form.elements[0].value;
var userpwd =_form.elements[1].value;
DWRUser.findUser(username,userpwd,showData);//showData回调函数
}
function showData(data){
alert("t");
if(data){
alert("y");
DWRUtil.setValue("userMsg","该用户名已经被注册,请更换您的用户名!");
}else{
DWRUtil.setValue("userMsg","恭喜您,该用户名尚未被注册!");
}
}
</script>
</HEAD>
<BODY>
<DIV id="logina"> <IMG src="images/login.gif"/> </DIV>
<DIV id="loginb">
<FORM action="toLogin.do" method="post" name="form1">
<%
String error=(String)request.getAttribute("error");
if(error!=null){
%>
<%=error%> <BR/>
<% } %>
用户登陆名: <INPUT name="UserID" type="text" class="text"/>
登陆密码: <INPUT name="UserPwd" type="password" class="text"/>
<INPUT name="submit" type="submit" class="btn_2k3" value="登陆" onclick="regUserChked(form1)">
</FORM>
<div id="userMsg"> </div>
</DIV>
</BODY>
</html>
加上 <include method="findUser"/>也不成,关键是连DWRUser都不能识别到,急啊,在线等!
望使用过dwr的高手解答!