spring mvc+DWR验证用户名是否存在,是最经典的案例了.标签:dwr,username,springmsgs,msgs,spring,innerHTML,用法,var From: https://blog.51cto.com/u_14230175/5923456
1 在DWR2里,注意配置的类名跟DWR1不同了
由 uk.ltd.getahead 变成了 org.directwebremoting 。
换上了新的配置
1<servlet>
2 <servlet-name>dwr-invoker</servlet-name>
3 <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
4 <init-param>
5 <param-name>debug</param-name>
6 <param-value>true</param-value>
7 </init-param>
8 <load-on-startup>1</load-on-startup>
9</servlet>
2 DTD也要改下了
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
3 dwr.xml
<?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">-->
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<convert converter="bean" match="liao.*"/>
<create creator="spring" javascript="MemberManager">
<param name="beanName" value="userFacade"/>
</create>
</allow>
</dwr>
其中userFacade就是spring里面的了.对应一个具体的校验类了
4 JSP页面端
function checkRepeat(s) {
var o = getElement(s);
if(o.value==""){
msgs[0].innerHTML="会员名不能为空!";
o.focus();
return false;
}
if (o) {
MemberManager.getMemberForName(o.value, showResult);
}
<SCRIPT language=javascript>
var msgs = document.getElementsByName("msg");
var springmsgs = document.getElementsByName("springmsgs");
function showResult(b) {
var username = getElement("username").value;
var usernamemsg = document.getElementsByName("usernamemsg");
if (b) {
springmsgs[0].innerHTML="";
msgs[0].innerHTML="对不起!你正准备注册的 "+username+" 已经被注册,请更换另外的会员名。";
} else {
usernamemsg.innerHTML="";
msgs[0].innerHTML="恭喜你!你可以注册 "+username+" 这个会员名。";
}
}