首先:struts.xml文件没有错
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple"/>
<package name="house-json" extends = "json-default">
<action name="login" class="com.pb.web.action.UserAction" method="login" >
<result type="json" name="success" ></result>
<result name="login" type="json"></result>
</action>
</package>
</struts>
其他地方貌似也没有什么错误!后来有仔细研究了一个上午,才发现,原来是UserAction里面的service使用了getter/setter方法,将其getter/setter方法去掉就好了。
package com.pb.web.action;
import java.util.Map;
import com.pb.base.action.BaseAction;
import com.pb.entity.HouseUser;
import com.pb.service.IUserService;
import com.pb.service.impl.UserServiceImpl;
import com.pb.util.Constant;
public class UserAction extends BaseAction {
private HouseUser user;
private IUserService service = new UserServiceImpl();
private String msg;
public String login(){
System.out.println(user.getUsername()+"--"+user.getPassword());
if(user!=null){
Map<String, Object> map = service.login(user);
user = (HouseUser)map.get("user");
System.out.println(user.getUsername()+"==22222=="+user.getPassword());
if(user!=null){
System.out.println(user.getUsername()+"--进来session这块儿"+user.getPassword());
this.session.put(Constant.LOGIN_USER, user);
msg = "true";
System.out.println("将返回success-------");
return "success";
}else{
msg = (String)map.get("msg");
}
}
System.out.println("将返回login");
return LOGIN;
}
//下面黄色部分删掉!!
public IUserService getService() {
return service;
}
public void setService(IUserService service) {
this.service = service;
}
public HouseUser getUser() {
return user;
}
public void setUser(HouseUser user) {
this.user = user;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}