简体   繁体   English

response.sendRedirect()不会重定向,不会引发任何错误

[英]response.sendRedirect() is not redirecting and does not throw any error

I try to develop a voice controlled web application. 我尝试开发语音控制的Web应用程序。 The problem is that it is not redirecting to the existing Webservlets url and does not shown any error messages. 问题在于它没有重定向到现有的Webservlets URL,并且没有显示任何错误消息。 Here is my doPost method in my Controller.java file: (in the second 'if' the redirect works fine, only in the third is not working.) 这是我的Controller.java文件中的doPost方法:(在第二个“如果”中,重定向工作正常,仅在第三个中不起作用。)

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    HttpSession session = req.getSession();

    if (req.getParameter("productId") != null){
        int prodID = Integer.parseInt(req.getParameter("productId"));
        cartHandler.add(prodID);
    }
    // LOGOUT
    if(req.getParameter("btn-logout") != null){
        if(session.getAttribute("uID") != null) {
            session.removeAttribute("uID");
            resp.sendRedirect("/");
        }
    }

    if(req.getParameter("allieStart") != null){
        String greeting = allieDaoJDBC.getAnswer("greeting");
        playSound.play(greeting);
        Integer react = speechRecognition.listen(allieDaoJDBC, cartHandler);
        if(react == 1){
            resp.sendRedirect("/cart");
        }else if(react == 2){
            resp.sendRedirect("/login");
        }
    }
}

Thank you guys in advance! 预先谢谢你们!

If you are sure allieStart is not null, then the problem must be with react (ie react is not 1 or 2.) Try adding another else condition, so you can be sure something will happen. 如果您确定allieStart不为null,则问题一定出在react (即react不是1或2。)尝试添加其他条件,这样就可以确定会发生什么。

    if(react == 1){
        resp.sendRedirect("/cart");
    }else if(react == 2){
        resp.sendRedirect("/login");
    }else{
        resp.sendRedirect("/login");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM