Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.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 如何在axios和spring控制器中处理重定向?_Java_Reactjs_Spring Boot_React Redux - Fatal编程技术网

Java 如何在axios和spring控制器中处理重定向?

Java 如何在axios和spring控制器中处理重定向?,java,reactjs,spring-boot,react-redux,Java,Reactjs,Spring Boot,React Redux,我正在尝试在我的web应用程序中创建cart,其中在spring controller中根据添加、更新的产品等进行重定向。我编写了axios get请求,该请求调用@RequestMapping(“/add/{productId}/product”),重定向到另一个请求映射,并返回结果。我把结果放在地图上,我可以在控制台上看到地图结果。但我无法在redux商店中获得结果 这是重定向链接show?result=updated。这是404错误 这是我的Axiso获取请求 export const g

我正在尝试在我的web应用程序中创建cart,其中在spring controller中根据添加、更新的产品等进行重定向。我编写了axios get请求,该请求调用
@RequestMapping(“/add/{productId}/product”)
,重定向到另一个请求映射,并返回结果。我把结果放在地图上,我可以在控制台上看到地图结果。但我无法在redux商店中获得结果

这是重定向链接
show?result=updated
。这是404错误

这是我的Axiso获取请求

export const getCart = (pt_id) => async dispatch => {
  const res = await axios.get(`http://localhost:8080/cart/add/${pt_id}/product`);

  dispatch({
    type: GET_CART,
    payload: res.data
  });
};
弹簧控制器

@RequestMapping("/{cartLineId}/update")
public String udpateCartLine(@PathVariable int cartLineId, @RequestParam int count) {
    String response = cartService.manageCartLine(cartLineId, count);        
    return "redirect:/cart/show?"+response;     
}

@RequestMapping("/add/{productId}/product")
public String addCartLine(@PathVariable int productId) {
    String response = cartService.addCartLine(productId);
    return "redirect:/cart/show?"+response;
}


@RequestMapping("/show")
public Map<String, Object> showCart(@RequestParam(name = "result", required = false) String result) {

    Map<String, Object> cartMap = new HashMap<String, Object>();
    cartMap.put("title", "Shopping Cart");

    if(result!=null) {
        switch(result) {

            case "added":
                cartMap.put("message", "Product has been successfully added inside cart!");
                cartService.validateCartLine();
                break;

            case "unavailable":
                cartMap.put("message", "Product quantity is not available!");
                break;

            case "updated":
                cartMap.put("message", "Cart has been updated successfully!");
                cartService.validateCartLine();
                break;
        }
    }
    else {
        String response = cartService.validateCartLine();
        if(response.equals("result=modified")) {
            cartMap.put("message", "One or more items inside cart has been modified!");
        }
    }

    cartMap.put("cartLines", cartService.getCartLines());
    return cartMap; 
}
响应

HTTP/1.1 404
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Access-Control-Allow-Origin: *
Set-Cookie: JSESSIONID=431DE0256413C4B665CFC94601E6DB9C; Path=/; HttpOnly
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/json;charset=UTF-8
Content-Language: en-US
Transfer-Encoding: chunked
Date: Tue, 05 Feb 2019 05:42:22 GMT
请求

GET /cart/show?result=updated HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Referer: http://localhost:3000/cart/add/28/product
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9

我做错了什么?

你找到解决办法了吗?成功登录后,Spring Security的formLogin重定向也遇到了类似的问题。
GET /cart/show?result=updated HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Accept: application/json, text/plain, */*
Origin: http://localhost:3000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
Referer: http://localhost:3000/cart/add/28/product
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9