ssy-come on 2017-07-27 00:48 采纳率: 0%
浏览 991
已结题

怎么把action处理得到的信息传到前端界面,angularjs怎么去接收打印msg

前台控制器:

var app = angular.module('myApp', []);

app.controller('LoginController', function ($scope, $http) {
$scope.submitForm= function(name,pw){

 $http(
    {  
        method  : 'GET',  
        url     : "http://localhost:8080/denglu/login.action",  
        params    :{username:'1',password:'1',
        /*   data:JSON.stringify({data:data代表的是这个$http()对象中包含了将会被当作消息体发送给服务器的数据。通常在发送POST请求时使用。
              'pageNum': pageNum,
              'pageSize': pageSize,
              'sort': sort,
             'edition': edition */

        },  // 传递数据作为字符串,从前台传到后台  
      }
      ).success(function (data) {

         alert(data);

        }).error(function() {

           alert("登录失败");

       });

     }

})

后台action:

@RequestMapping("/login")

public ModelAndView login(String username,String password,HttpServletResponse response) {
ModelAndView m = new ModelAndView();
User user = new User();
user.setUsername(username);
user.setPassword(password);

    System.out.println(username+password+"********************************");

    User a = ilogin.login(user);
    System.out.println(a+"********************************");
    String msg="";
    PrintWriter out = null;
    try {
        out = response.getWriter();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }  
    if(a != null){
         msg="登录成功";
        out.print(msg);
        /*msg="登录成功";
        m.addObject("msg", msg);
        m.setViewName("index.jsp");*/   
    }
    else{
         msg="失败";
          out.print(msg);       
    }
    return m;



  现在的情况就是action可以接收到前台传的参数,也能查到数据库中有值,但是前端界面一直走error,请大神指点,或者哪位大神给发下ajax的传接收数据的例子
  • 写回答

2条回答

  • 微wx笑 Java领域优质创作者 2017-07-27 02:39
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器