zoukankan      html  css  js  c++  java
  • action返回了success但是页面也没有局部刷新问题

    错误信息

    首先: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;
        }
    }

  • 相关阅读:
    11111 Generalized Matrioshkas
    Uva 442 Matrix Chain Multiplication
    Uva 10815 Andy's First Dictionary
    Uva 537 Artificial Intelligence?
    Uva 340 MasterMind Hints
    SCAU 9508 诸葛给我牌(水泥题)
    Uva 10420 List of Conquests(排序水题)
    Uva 409 Excuses, Excuses!
    10/26
    11/2
  • 原文地址:https://www.cnblogs.com/yaojiu/p/3508427.html
Copyright © 2011-2022 走看看