你的AuctionManager 这个类配置好了,但你也没有把你的LoginAction 配置到spring里啊,如果你不用spring管理action的话那就要手工得到AuctionManager 他的实例才ApplicationContext ctx = new ClassPathXmlApplication("applicationContext.xml");AuctionManager a = (AuctionManager )ctx.getBean("auctionManager");然后再给action里的属性赋值你现在肯定空指针

解决方案 »

  1.   

    这个是我修改后的代码:
    package com.ribert.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;
    import com.ribert.service.AuctionManager;public class LoginAction extends ActionSupport { private String userName; private String passwrod;

    private AuctionManager agr; public AuctionManager getAgr() {
    return agr;
    } public void setAgr(AuctionManager agr) {
    this.agr = agr;
    } @Override
    public String execute() throws Exception { Map session = ActionContext.getContext().getSession();// 通过ActionContext对象访问web应用的session
    Integer userId = agr.validLogin(userName, passwrod);
    if (userId != null) {
    session.put("userId", userId);
    return SUCCESS;
    } else {
    addActionError("用户名/密码不匹配");
    return "failure";
    }
    } public String getPasswrod() {
    return passwrod;
    } public void setPasswrod(String passwrod) {
    this.passwrod = passwrod;
    } public String getUserName() {
    return userName;
    } public void setUserName(String userName) {
    this.userName = userName;
    }}
    AuctionManager在applicationContext.xml中的配置如下:
    <bean id="auctionManager"
    class="com.ribert.service.impl.AuctionManagerImpl">
    <property name="userDao" ref="userDao" />
    </bean>也对AuctionManager创建叻自动生成业务代理。
    userDao在daoContext.xml中的配置如下:
    <bean id="daoTemplate" abstract="true">
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>
              <bean id="userDao" class="com.ribert.dao.impl.UserDaoImpl"
    parent="daoTemplate" />
    在web.xml中daoContext.xml和applicationContext.xml都已配置好叻。
    LoginAction在applicationContext.xml中配置如下:
    <bean id="loginAction" class="com.ribert.action.LoginAction">
    <property name="agr" ref="auctionManager" />
    </bean>

    不知道这红色代码有没有配置错误。我经过以上的修改后还是出现同样的问题?麻烦高手看看,谢谢叻!
      

  2.   

    还请看你的struts-config和web.xml代码啊!你是用的哪一种整合啊!