Servlet没有正确重定向

时间:2015-09-27 04:06:13

标签: java jsp servlets redirect

我遇到以下问题: 我从.jsp获取参数,它发送给一个函数,但在那里,它保存了DB中的参数,但重定向到错误文件。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        try{
                        if (request.getParameter("form").equals("insertEmpresa")){
                            inserirEmpresa(request,response);
                        }else if (request.getParameter("form").equals("insertUsuario")){
                            inserirUsuario(request, response);
                        }
                        else if (request.getParameter("form").equals("login")){
                            processarLoginUsuario(request,response);
                        }
        }catch(Exception e){
            response.sendRedirect("erro.jsp");
        }

servlet访问inserirEmpresa函数,但当它进入时,它会转到BO,DAO,将数据保存在DB中,但重定向错误(我确定它已经得到了进入这个特定的错误,已经尝试评论其他部分

protected void inserirEmpresa(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, Exception {
        EmpresaBO ebo = new EmpresaBO();
        try{
            if(ebo.inserir(request.getParameter("cnpj"), request.getParameter("nome"), request.getParameter("endereco"), Integer.parseInt(request.getParameter("telefone")),
                    Integer.parseInt(request.getParameter("ddd")), request.getParameter("email"), request.getParameter("senha")) == true){
                request.getRequestDispatcher("index.jsp").forward(request, response);
            }else{
                System.out.println("Erro no inserirEmpresa");
                request.setAttribute("msg", "Ocorreu um erro no cadastro!");
                request.getRequestDispatcher("erro.jsp").forward(request, response);
            }
        }catch(Exception e){
            throw new Excecao(e);
        }
    }

谢谢!

0 个答案:

没有答案