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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog