ssh+jquery整合问题
异步请发送到后台,后台处理后,返回了,但前台Jquery的回调函数没有触发。
以下是我的相关配置文件和代码。
package com.gifer.web;
import java.util.List;
import com.gifer.model.LoginUser;
import com.gifer.service.LoginUserService;
import com.opensymphony.xwork2.ActionSupport;
/**
* @author zhongdc
*
*/
public class LoginUserAction extends ActionSupport {
private static final long serialVersionUID = 1127293641745744474L;
private LoginUserService userManager;
private LoginUser user;//单个用户对象
private List<LoginUser> userInfosList;//用户列表
private String result;//请求结果标识
public LoginUserService getUserManager() {
return userManager;
}
public void setUserManager(LoginUserService userManager) {
this.userManager = userManager;
}
public LoginUser getUser() {
return user;
}
public void setUser(LoginUser user) {
this.user = user;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public List<LoginUser> getUserInfosList() {
return userInfosList;
}
public void setUserInfosList(List<LoginUser> userInfosList) {
this.userInfosList = userInfosList;
}
public String returnListUser() throws Exception{
try {
this.userInfosList= this.userManager.findAll();
this.result="true";
} catch (Exception e) {
e.printStackTrace();
this.result="false";
}
return "ListUser";
}
public String returnSaveUser() throws Exception{
try {
this.userManager.save(user);
this.result="true";
} catch (Exception e) {
e.printStackTrace();
this.result="false";
}
return "SaveUser";
}
public String returnDeleteUser() throws Exception{
try {
this.userManager.delete(user);
this.result="true";
} catch (Exception e) {
this.result="false";
e.printStackTrace();
}
return "DeleteUser";
}
public String returnFindUser() throws Exception{
try {
this.user= this.userManager.findById(this.user.getUserId());
this.result="true";
} catch (Exception e) {
e.printStackTrace();
this.result="false";
}
return "FindUser";
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="com.gifer.web" namespace="/" extends="json-default">
<!-- 一个action接收多个请求的配置方法 -->
<action name="UserAction" class="UserManagerAction">
<result name="ListUser" type="json"></result>
<result name="SaveUser" type="json"></result>
<result name="DeleteUser" type="json"></result>
<result name="FindUser" type="json"></result>
</action>
</package>
</struts>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="gifer"></property>
<property name="password" value="gifer"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/gifer/model/LoginUser.hbm.xml</value>
</list>
</property>
</bean>
<bean id="LoginUserDAO" class="com.gifer.dao.LoginUserDAO">
<property name="sessionFactory">
<ref bean="sessionFactory"></ref>
</property>
</bean>
<bean id="LoginUserService" class="com.gifer.service.LoginUserService">
<property name="dao">
<ref bean="LoginUserDAO" />
</property>
</bean>
<bean id="UserManagerAction" class="com.gifer.web.LoginUserAction" scope="prototype">
<property name="userManager">
<ref bean="LoginUserService"/>
</property>
</bean>
</beans>
js
//向服务器发送表达数据
$("#regRe").click(function() {
//把表单的数据进行序列化
var params = $("form").serialize();
//使用jQuery中的$.ajax({});Ajax方法
$.ajax( {
url : "UserAction!returnSaveUser",//!前面是Action的名字,!后面是执行的方法名
type : "POST",
data : params,
dataType : "json",
success : function(data) {
if(data.result=="true"){
alert("注册成功!");
}
//清空显示层中的数据
$("#message").html("");
//为显示层添加获取到的数据
//获取对象的数据用data.user.属性
$("#message").append(
"<div><font color='red'>用户ID:"
+ data.user.userId
+ "</font></div>").append(
"<div><font color='red'>用户名:"
+ data.user.userName
+ "</font></div>").append(
"<div><font color='red'>密码:"
+ data.user.password
+ "</font></div>")
}
});
});
});
...全文
相关推荐
SSH+ajax+jquery面试实例
这是一个SSH+ajax+jquery面试实例,里面包括两具DB文件,myeclipse开发的全部源码,是一个学习SSH+ajax+jquery的不错实例
最简单java视频网站ssh+jquery+mysql
1.架构设计 2.主界面 3.点播页面 4.直播页面 5.视频其他页面
ssh简单整合(struts2)
NULL 博文链接:https://tk-it-2012.iteye.com/blog/1662294
SwfUpload+ssh+easyui实现的文件上传
swfupload结合easyui以及ssh框架实现的文件上传,并且将文件的节本信息存到数据库中
ssh+easyui+dategrid
框架版本可能有点低,但不影响功能实现


Web 开发
