日期:2014-05-19 浏览次数:20711 次
<script type="text/javascript"> $(document).ready( function(){ $("#check").blur(function(){ var params=$("#check").serialize(); $.ajax({ url:"check.action", type:"post", dataType:"json", data:"WUser.userName="+$("#check").val(),--[color=#FF0000]这样传值是否正确??[/color] success:update_page }); }); }) ; function update_page(info){ var json=eval(info); var str=json.info; $("#information").html(str); } </script> </head> <body> <s:form action="register" name="register" method="post"> <s:textfield id="check" name="WUser.userName" label="账号"></s:textfield><div id="information"></div><br/>
public class CheckAction extends ActionSupport{ /** * */ private static final long serialVersionUID = 1L; private WUser user=new WUser(); private String info; public String getInfo() { return info; } public void setInfo(String info) { this.info = info; } public WUser getUser() { return user; } public void setUser(WUser user) { this.user = user; } public String execute()throws Exception { System.out.println(user.getUserName());//打印接受到的userName[color=#FF0000]总是显示null??[/color] BeanFactory bf = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext()); Dao dao = (Dao)bf.getBean("Daohibernate"); List name=dao.queryUser(user.getUserName()); if(name==null){ info="恭喜你可以使用"; }else{info="用户已经存在";} System.out.println(info); return SUCCESS; } }
data:"WUser.userName="+$("#check").val(),--[color=#FF0000]
------解决方案--------------------