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

Asked

Viewed 542 times

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 web.xml, when the user enters an unknown link or leads to one of these errors, to be redirected to the Controller, to handle the page inside the Controller itself.

The corresponding jsp pages are already created, inside the error folder, as requested by Vraptor, using Tomcat or Glassfish, the page is empty.

  • 1

    Do you need to redirect to each specific Controller? has tried using result.forwardTo(); ?

  • In fact, I want you to redirect to that controller only, so that it can handle the error-pages.

  • 1

    I don’t quite understand this one tratar the error pages, it would not be better to add some message on the screen with a button to redirect to the previous page?

  • 1

    That way your @Wellingtonavelino I’m already doing, but it doesn’t show some components on the page, which are loaded on the server, through an Intercept, so I’ll have to go through a controller to trigger the Intercept and I load other components through this controller, and the tratar would load these different components on the server, and record an audit, differently for each error, in the database, so I need the Controller.

  • 1

    I get it, I’m going to read the doc, because a few months ago I stopped using Vraptor

  • 1

    http://chat.stackexchange.com/rooms/11910/estouro-de-pilha @TiagoFerezin

  • 1

    @Wellingtonavelino found the solution and posted

Show 2 more comments

1 answer

1


I solved the problem as follows:

I created the 404.jsp page that will only redirect to the Controller so:

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>

Which will load jsp error404.jsp through the Controller via the Post method so the user doesn’t have access to the 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 have directed 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>

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.