0

我正在开发一个使用 struts2、jquery、ajax 检查用户可用性的网页。它工作正常。在我使用 spring、hibernate、struts2 集成同一页面后,它停止工作。不知道我做错了什么。

我的SpringConfiguration.xml代码是

<bean id="chkuserdao" class="com.dao.DaoClass">
  <property name="sessionfactory" ref="sessionFactory"></property>
</bean>
<bean id="chkuser" class="com.action.check" >
  <property name="chkuserdao" ref="chkuserdao"></property>
</bean>

web.xml的是

<servlet>
  <servlet-name>ex1</servlet-name>
  <servlet-class> com.action.check </servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>ex1</servlet-name>
  <url-pattern>/check</url-pattern>
</servlet-mapping>

check.java

List a=new ArrayList();
String uname = request.getParameter("uname");
a=chkuserdao.getUserName(uname);

if (a.size()<=0) 
{
    out.println("<font color=green><b>"+uname+"</b> is avaliable");
}

我的 JSP 是

 <script src="jquery.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function(){
 $(".uname").change(function(){
 var uname = $(this).val();
 if(uname.length > 3){
 $(".status").html("<img src='images/loading.gif'><font color=gray> Checking  
 availability...</font>");
 $.ajax({
 type: "POST",
 url: "/check",
 data: "uname="+ uname,
 success: function(msg){
 $(".status").ajaxComplete(function(event, request, settings){
 $(".status").html(msg);
 });}});}
 else{
 $(".status").html("<font color=red>username shold be more than<b>3</b> chars</font>");
 }});});
 </script>
4

0 回答 0