0 0

dwr 调用javaBean失败5

请大家耐心看完
dwr:
<dwr>
    <!-- 检查用户名是否存在 ValidateName的映射文件-->
    <allow>
      <create  creator="spring" javascript="ValidateName" >
          <param name="beanName" value="validateName"/>
          <include method="valid"/>
          <include method="checkValiCode(String vercode)"/>
      </create>
     
     </allow>
</dwr>


spring:

	<bean id="validateName"
		class="com.ssh.common.bean.ValidateName">
		<property name="userService">
			<ref local="userService" />
		</property>
	</bean>

html:

<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
		<title>用户注册</title>
		<script src="js/prototype.js" type="text/javascript"></script>
		<script type="text/javascript" src="dwr/engine.js"> </script>
		<script type="text/javascript" src="dwr/util.js"> </script>
		<script type="text/javascript" src="dwr/interface/ValidateName.js"></script>
	
		<script language="JavaScript">
			function validateName()
			{   
			 
				var username=$F("username");
				ValidateName.valid(username,showresult);
			}
			function showresult(result)
			{	
				$("tip").innerHTML = result;
			}	
			function refresh(){
				$("authImg").src="authImg?now="+new Date();
			}
			
			function check(){
			    alert();
			    var valicode=$F("vercode");
			    alert(valicode);
				ValidateName.checkValiCode(valicode,checkCode);
			}
			function checkCode(result)
			{	
				$("tipcode").innerHTML = result;
			}	
			
		</script>
	</head>
	<body>
		<center>
			<h3>
				请输入注册信息
			</h3>
			<br><br>
			<s:fielderror />
			<s:actionerror />
			
			<form action="/sclBBS/Regist.action" method="post" >
				<table border="0">
					<tr>
						<td>
							用户名:
						</td>
						<td>
							<input type="text" id="username" name="username" onblur="validateName();" style="width:150px"  />
						  <span id="tip" style="color: red; font-weight: bold"></span>
						</td>
					</tr>
					<tr>
						<td>
							密&nbsp;&nbsp;&nbsp;&nbsp;码:
						</td>
						<td>
							<input type="password" id="password" name="password" style="width:150px"   />
						</td>
					</tr>
					<tr>
						<td>
							确认密码:
						</td>
						<td>
							<input type="password" id="password" name="password" style="width:150px"   />
						</td>
					</tr>
					<tr>
						<td>
							电&nbsp;&nbsp;&nbsp;&nbsp;邮:
						</td>
						<td>
							<input type="text" id="email" name="email" style="width:150px" />
						</td>
					</tr>
					<tr>
						<td>
							验证码:
						</td>
						<td>
							<input type="text" id="vercode" onblur="check();" name="vercode" style="width:150px" />
							  <span id="tipcode" style="color: red; font-weight: bold"></span>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<input type="submit" value="注册" />
						</td>
					</tr>
				</table>
			</form>
			验证码如图:
			<img src="authImg" id="authImg" />
			看不清?
			<a href="#" onClick="refresh()">单击此处刷新</a>
		</center>
	</body>
</html>

javabean:

/**
*
* @author <a href="mailto:flustar2008@163.com">flustar</a>
* @version 1.0
* Creation date: Dec 25, 2007 6:32:19 PM
*/
package com.ssh.common.bean;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.ssh.entity.user.service.IUserService;

public class ValidateName {
	private IUserService userService;
	public String valid(String username){//用来检查用户名是否存在
		String result=null;
		if("".equals(username)||username==null) {
			result="请填写用户名";	
		}
		else if(!userService.validateName(username)){
			result="恭喜,"+username+" 可以使用";
		}else{
			result=username+" 已存在,请换一个用户名";
		}
		return result;
	}
	
	
    public String checkValiCode(String vercode){
    	String result = "";
		Map session = ActionContext.getContext().getSession();
		String ver2 = (String) session.get("rand");
		if(!vercode.equals(ver2)){
			result="验证码不正确";
		}else{
			result = "验证码正确";
		}
		return result; 
    }
	public IUserService getUserService() {
		return userService;
	}
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	
	
}


其中valid方法可以用,但checkValiCode不行,是哪里出问题了?
问题补充:
ValidateName.checkValiCode(valicode,checkCode); 
checkCode是回调
DWR 
2008年8月15日 14:27

1个答案 按时间排序 按投票排序

0 0

ValidateName.checkValiCode(valicode,checkCode);  

 public String checkValiCode(String vercode){  
         String result = "";  
         Map session = ActionContext.getContext().getSession();  
         String ver2 = (String) session.get("rand");  
         if(!vercode.equals(ver2)){  
             result="验证码不正确";  
         }else{  
             result = "验证码正确";  
         }  
         return result;   
     }  

函数声明只有1个参数,你传入2个参数了.

2008年8月18日 11:35

相关推荐

Global site tag (gtag.js) - Google Analytics