Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java servlet未读取$http GET参数_Java_Angularjs_Servlets - Fatal编程技术网

Java servlet未读取$http GET参数

Java servlet未读取$http GET参数,java,angularjs,servlets,Java,Angularjs,Servlets,我正在从$http调用发送用户ID。servlet正在命中,但它无法接收请求参数。我正在通过request.getParameter(“userId”)获取请求参数 这是密码 $scope.getDetailsFromServer = function() { $http({ method: 'GET', url: 'dashboardDetailsOfUser', hea

我正在从$http调用发送用户ID。servlet正在命中,但它无法接收请求参数。我正在通过request.getParameter(“userId”)获取请求参数

这是密码

    $scope.getDetailsFromServer = function() {      
        $http({
           method: 'GET',           
           url: 'dashboardDetailsOfUser',
           headers: {'Content-Type': 'application/x-www-form-urlencoded'},
           data:"userId="+ $scope.userId
           }).success(function (data){
            $scope.status=data;
           }).error(function(data, status, headers, config) {
            alert("error");
       });      
    }
我的servlet代码
Angular或Servlet的代码中是否缺少任何内容

客户端发送GET请求,因此servlet使用请求主体来填充请求参数


发送帖子并在servlet中使用
doPost
,或者获取并在url中包含userId参数。

是的,您的命名不一致。你说你在用用户id,但你在找用户id。另外,请将您的代码示例更多地集中在您遇到的这个问题上。@ErikPragt,好的,我已经编辑了这个问题。那是个打字错误。请检查它您的HTTP get可能是错误的。它需要如下所示:$http({url:'dashboardDetailsOfUser',方法:“GET”,参数:{userId:“123”})@这是正确的格式。这是唯一的选择吗?我不确定。如果我不高兴,请纠正我wrong@Syed请参见servlet 3.1。规范,第3.1.1章,参数可用时。作为第三种选择,您还可以自己解析请求主体
    @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    String result = "";
    try {
        con = ds.getConnection();
        stmt = con.createStatement();
        String user_id = request.getParameter("userId");
        System.out.println("User ID :"+user_id);
        String json = new Gson().toJson(result);
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");         
        response.getWriter().write(json);
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (stmt != null)
                stmt.close();
            if (con != null)
                con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}