当前位置: 代码迷 >> Java Web开发 >> Spring注入后Action接收不到!该如何解决
  详细解决方案

Spring注入后Action接收不到!该如何解决

热度:264   发布时间:2016-04-17 10:58:10.0
Spring注入后Action接收不到!!
我的Spring在服务器启动时被注入,但是在Action中,当Action被访问,那么注入的属性都变为null~求解啊!!!


2011-10-11 17:57:53 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
ServiceDAO真心注入了 sun.common.ServiceDAO@71cb25
com.news.app.user.UserService@c510e3
2011-10-11 17:57:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2011-10-11 17:57:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory Test
2011-10-11 17:57:56 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-80
2011-10-11 17:57:56 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-8009
2011-10-11 17:57:56 org.apache.catalina.startup.Catalina start
信息: Server startup in 6294 ms
null
com.sun.dao.FirstTypeDAOImpl@993730
Action代码
Java code
package com.news.app.user;import java.sql.SQLException;import com.sun.dao.FirstTypeDAOImpl;import sun.common.SunActionSupport;public class UserAction extends SunActionSupport{    private UserService userService;    private FirstTypeDAOImpl firsttypeDAO;            public FirstTypeDAOImpl getFirsttypeDAO() {        return firsttypeDAO;    }    public void setFirsttypeDAO(FirstTypeDAOImpl firsttypeDAO) {        this.firsttypeDAO = firsttypeDAO;    }    public UserService getUserService() {        return userService;    }    public void setUserService(UserService userService) {        this.userService = userService;    }    @Override    public String add() throws Exception {        // TODO Auto-generated method stub        return null;    }    @Override    public String addView() throws Exception {        // TODO Auto-generated method stub        return null;    }    @Override    public String delete() throws Exception {        // TODO Auto-generated method stub        return null;    }    @Override    public String edit() throws Exception {        // TODO Auto-generated method stub        return null;    }    @Override    public String editView() throws Exception {        // TODO Auto-generated method stub        return null;    }    @Override    public String list() throws Exception {        // TODO Auto-generated method stub        return null;    }        //登录LoginAction    public String Login() throws SQLException{        System.out.println(userService+"\n"+firsttypeDAO);//        if(condition=="login"){//            System.out.println(user.getUser_name());////            getSession().put("user_name", user.getUser_name());////            getSession().put("password", user.getPassword());////            getSession().put("user_lvl", user.getUser_lvl());//            System.out.println("登录成功");//            return LOGIN;//        }//        else{//            System.out.println("登录失败");//            return ERROR;//        }        return "login";            }    @Override    public String search() throws Exception {        // TODO Auto-generated method stub        return null;    }}

Service代码
Java code
package com.news.app.user;import java.sql.SQLException;import sun.common.ServiceDAO;import sun.common.newsService;import com.sun.dao.UserDAO;import com.sun.vo.UserExample;public class UserService implements newsService{    private ServiceDAO userService;    private String password;    private int user_lvl;    private String user_name;        public int getUser_lvl() {        return user_lvl;    }    public void setUser_lvl(int userLvl) {        user_lvl = userLvl;    }    public String getPassword() {        return password;    }    public String getUser_name() {        return user_name;    }    public void setPassword(String password) {        this.password = password;    }    public void setUser_name(String userName) {        user_name = userName;    }    public ServiceDAO getUserService() {        return userService;    }    public void setUserService(ServiceDAO userService) {        System.out.println(this);        this.userService = userService;    }    public String addService() throws SQLException {        // TODO Auto-generated method stub                UserExample example = new UserExample();        com.sun.vo.UserExample.Criteria criteria = example.createCriteria();        criteria.andPasswordEqualTo(password).andUserNameEqualTo(user_name);        //判断是否有此人        if(!userService.getUserDAO().selectByExample(example).isEmpty()){            //用户信息及等级存入session                        user_lvl=userService.getUserDAO().selectByExample(example).get(0).getUserLvl();                        return "login";            }        return "error";    }    public String addViewService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    public String deleteService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    public String editService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    public String editViewService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    public String listService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    public String searchService() throws SQLException {        // TODO Auto-generated method stub        return null;    }    }
  相关解决方案