检索POST参数Angularjs

时间:2015-07-31 10:31:32

标签: javascript angularjs post http-post-vars

如何以角度检索发布数据。

我有角度的应用程序。

 My script.js
 ************
 $routeProvider.when('/test1', {
    templateUrl : 'html/test1.html',
controller : 'test1Controller'
}).when('/test2', {
templateUrl : 'html/test2-screen.html',
controller : 'test2Controller'
})

步骤:1

我有一些代码可以从http://myapp.com/myapp#test1重定向到另一个网址,例如https://stackoverflow.com/processdata

步骤:2

它会将一些POST数据返回到我的返回URL,返回的URL是 http://myapp.com/myapp#test2,这是我的角度页面。

在stackoverflow上提到这个, How to read the post request parameters using javascript

这很好,但我需要解决方案。

查询:

如何阅读页面http://myapp.com/myapp#test2

中的POST参数

可能的解决方案如下:

将返回网址从angular url更改为某个spring mvc url 例如

@Controller
@RequestMapping("/return")
public class TestController{
  @RequestMapping(value = "/abc",method = RequestMethod.POST)
public String getPostParam (ModelMap model,HttpSession session,HttpServletRequest request) {
        //Step : 1 retrieve the params here
        Enumeration params = request.getParameterNames(); 
        while(params.hasMoreElements()){
        String paramName = (String)params.nextElement();
        System.out.println("Attribute Name - "+paramName+", Value - "+request.getParameter(paramName));

    }
      //Step 2 : save them in session and redirect it to my angular page 
      response.sendRedirect("/test2");
    }
}

这是一种更好的方法吗?或者有人可以提出别的建议???

0 个答案:

没有答案