How to redirect the link in web.xml from vraptor to a Controller?

2

I have the following codes below:

web.xml:

<error-page>
    <error-code>404</error-code>
    <location>/error/404</location>
</error-page>

<error-page>
    <error-code>500</error-code>
    <location>/error/500</location>
</error-page>

ErrorController.java:

@Controller
@Resource
public class ErrorController {

    public ErrorController(){

    }

    @Path("/error/404")
    public void error404(){

    }

    @Path("/error/500")
    public void error500(){

    }

}

I would like the web.xml, when the user enters an unknown link or that leads to one of these errors, be redirected to the Controller, to treat the page within the same Controller.

The respective jsp pages are already created inside the error folder, as requested by VRaptor, using TomCat or GlassFish, the page is left blank.

    
asked by anonymous 15.07.2015 / 20:54

1 answer

1

I solved the problem as follows:

I created the 404.jsp page which will only redirect to the Controller, thus:

404.jsp:

<body>
    <div id="errorContent"></div>

    <script type="text/javascript">
    console.log("Iniciando JQuery(document).ready");
    jQuery(document)
            .ready(
                    function() {

                        irUrl = "/site/error/404";

                        $
                                .ajax({
                                    url : irUrl,
                                    type : "POST",
                                    beforeSend : function() {



                                        contexto = "/site";

                                        $.blockUI({
                                            message : "erro 404",
                                            theme : false,
                                            baseZ : 99999
                                        });

                                    },
                                    success : function(data) {
                                        $.unblockUI();
                                        $("#errorContent").html(data);

                                    },
                                    error : function(data) {
                                        // alert('error data: ' + data);

                                        $.unblockUI();

                                        $("#errorContent").html(data);

                                    }
                                });

                    });
  </script>
</body>

It will load the jsp error404.jsp through the Controller by the Post method so the user does not have access to url:

ErrorController.java:

@Controller
@Resource
public class ErrorController {

    public ErrorController() {

    }

    @Post("/error/404")
    public void error404() {

    }

    @Post("/error/500")
    public void error500() {

    }

}

In web.xml I redirected to this 404.jsp:

web.xml:

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/jsp/error/404.jsp</location>
</error-page>

<error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/jsp/error/500.jsp</location>
</error-page>

I created a custom jsp page 404 (error404.jsp) and made both of them for 500.

    
16.07.2015 / 20:38