Json 集成S2SH 问题 json无法调用到 action里面 由spring注入的类的方法
时间:2011-01-11
来源:互联网
js代码:
$(document).ready(function(){
$("#username").blur(function(){
var param = {
username: $("#username").val()
}
$.post("registerJsonAction.action", param, function checkName(data){
alert(data);
if (data == 'exist') {
$("#username_error").html("<font color ='red'>该用户名已存在!</font>");
}
else {
$("#username_error").html("<font color ='green'>恭喜该用户名可以注册!</font>");
}
}, "json");
});
});
struts2 action 代码:
@Component("register")
@Scope("prototype")
public class RegisterJsonAction extends ActionSupport {
private static final long serialVersionUID = 7044325217725864312L;
private String username;
private String tip;
private UserService userService;
/*@JSON(serialize = false)
public UserService getUserService() {
return userService;
}*/
@Resource(name = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute() throws Exception {
if (userService.checkByName(getUsername())) {
tip = "exist";
} else {
tip = "not_exist";
}
return SUCCESS;
}
}
我已经 试过 用Junit4 测试过方法 是可以的 json+struts2+hibernate 也是可以 但是集成了spring2.5 就不行了
希望高手帮帮忙为什么 提示 是 500错误 说我的“userService.checkByName(getUsername())” 方法null 返回空指针异常 ! 谢谢大家
$(document).ready(function(){
$("#username").blur(function(){
var param = {
username: $("#username").val()
}
$.post("registerJsonAction.action", param, function checkName(data){
alert(data);
if (data == 'exist') {
$("#username_error").html("<font color ='red'>该用户名已存在!</font>");
}
else {
$("#username_error").html("<font color ='green'>恭喜该用户名可以注册!</font>");
}
}, "json");
});
});
struts2 action 代码:
@Component("register")
@Scope("prototype")
public class RegisterJsonAction extends ActionSupport {
private static final long serialVersionUID = 7044325217725864312L;
private String username;
private String tip;
private UserService userService;
/*@JSON(serialize = false)
public UserService getUserService() {
return userService;
}*/
@Resource(name = "userService")
public void setUserService(UserService userService) {
this.userService = userService;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
public String execute() throws Exception {
if (userService.checkByName(getUsername())) {
tip = "exist";
} else {
tip = "not_exist";
}
return SUCCESS;
}
}
我已经 试过 用Junit4 测试过方法 是可以的 json+struts2+hibernate 也是可以 但是集成了spring2.5 就不行了
希望高手帮帮忙为什么 提示 是 500错误 说我的“userService.checkByName(getUsername())” 方法null 返回空指针异常 ! 谢谢大家
作者: Jokerfly0209 发布时间: 2011-01-11
CSS code
用接口
DriveModel
实现里面的方法
看看能不能获取到UserService 类
作者: leehuat 发布时间: 2011-01-11
你的struts2的对象要交给spring来创建完成,你这两个框架的整合有做了吗?
作者: licip 发布时间: 2011-01-11
一看就是没整合
作者: fangtao8798 发布时间: 2011-01-11
引用 2 楼 licip 的回复:
你的struts2的对象要交给spring来创建完成,你这两个框架的整合有做了吗?
你的struts2的对象要交给spring来创建完成,你这两个框架的整合有做了吗?
我整合了啊 struts 不用交给spring吧 我在web 里面 设置了 listener 和 spring的 xml路径了
作者: Jokerfly0209 发布时间: 2011-01-11
我单独在 一个测试类里面 试过 ssh 有没集成 测试返回的结果是我所要的结果 应该是没问题的 就是 在struts
的 action里面 那个userService 值是 null (调试的结果)
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
的 action里面 那个userService 值是 null (调试的结果)
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:application.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
作者: Jokerfly0209 发布时间: 2011-01-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28