gpt4 book ai didi

java - 尝试从 AngularJS 到 Spring MVC 使用 $http.post 服务时出现错误 415 - Maven

转载 作者:行者123 更新时间:2023-12-01 09:00:08 25 4
gpt4 key购买 nike

我试图在单击从 Spring Forms + JSTL + Spring MVC 迁移到 AngularJS + Spring MVC 的登录按钮时检查用户是否存在,但我'我收到此错误:

Failed to load resource: the server responded with a status of 415 (Tipo de Medio No Soportado)

我是 AngularJS 和 Spring 的新手,所以请友善一点。

这是我的 Java Controller :

@Controller
@SessionAttributes("empleado")
public class LoginController {

@Autowired
private IServiceEmpleado serviceEmpleado;

@RequestMapping(value="/login/check", method = RequestMethod.POST,consumes = {"application/json;charset=UTF-8"}, produces={"application/json;charset=UTF-8"})
public @ResponseBody void login(@RequestBody LoginDTO login, HttpSession session) throws ServicioException{


Empleado empleado = serviceEmpleado.correctLogin(login.getDni(), login.getPassword());

session.setAttribute("empleado",

empleado);

}
}

这是我的 AngularJS Controller :

angular.module('electronicaDonPepe')
.controller('LoginController', ['$scope', '$http', '$state', '$stateParams',
function($scope, $http, $state, $stateParams) {

$scope.login = function(){
var param = {
dni: $scope.usuario.dni,
contrasenia: $scope.usuario.contrasenia
};

$http.post('http://localhost:8585/electronicaDonPepe/login/check', param).then(function(){
$state.go('login');
});
};
}]);

最后,这是错误:

Request URL:http://localhost:8585/electronicaDonPepe/login/check
Request Method:POST
Status Code:415 Tipo de Medio No Soportado
Remote Address:[::1]:8585
Response Headers
view source
Cache-Control:no-cache
Cache-Control:no-store
Content-Language:es
Content-Length:1120
Content-Type:text/html;charset=utf-8
Date:Thu, 19 Jan 2017 13:44:02 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:es-ES,es;q=0.8
Connection:keep-alive
Content-Length:43
Content-Type:application/json;charset=UTF-8
Cookie:JSESSIONID=4E1E018490CC15F29FBE205132C2CACD; __ngDebug=true
Host:localhost:8585
Origin:http://localhost:8585
Referer:http://localhost:8585/electronicaDonPepe/
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Request Payload
view source
{dni: "34631248", contrasenia: "34631248"}
contrasenia
:
"34631248"
dni
:
"34631248"

还有一些 AngularJS Batarang 提示:

Module "ui.router.util" was created but never loaded.
Module "ui.router.router" was created but never loaded.
Module "ui.router.state" was created but never loaded.
Module "ui.router" was created but never loaded.
Module "ui.router.compat" was created but never loaded.
Module "electronicaDonPepe" was created but never loaded.

我做了研究,但在我读到的每个示例中,这似乎都是一个非常特殊的情况。提前致谢。

最佳答案

{dni: "34631248", contrasenia: "34631248"}

这是您的错误。您正在传递无效的 JSON 格式类型。尝试使用任何在线格式化程序,您会发现它会给您带来错误。

{"dni": "34631248", "contrasenia": "34631248"}

这是 Json 格式类型的正确方式。希望对您有帮助。现在两者正在传递字符串。

  var param = {
"dni": $scope.usuario.dni,
"contrasenia": $scope.usuario.contrasenia
};

然后尝试一下。

关于java - 尝试从 AngularJS 到 Spring MVC 使用 $http.post 服务时出现错误 415 - Maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41743756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com