How to determine which HTML file should be displayed as input in Jersey?

Asked

Viewed 925 times

5

I’m trying to find a way to provide a correct entry page in Jersey. A login page when there is no logged in user, otherwise I should display another homepage that will call Restful services developed with Jersey and that will change the interface of the home page when there is logged in user.

Below the file configuration web.xml:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>login.html</welcome-file>
</welcome-file-list>

Any solution is valid as long as it uses the web.xml to facilitate. I don’t think it convenient to have to create a service to return each of these pages.

1 answer

2


If the idea is to direct non-logged users to a particular page, you can create a filter (Filter) to check the user’s status and, if not logged in, redirect it to the correct URL.

Also, the same filter could check if the URL accessed is the root of the application to then redirect the user to the respective homepage.

When developing applications with Jersey, I avoid using static pages and also the <welcome-file-list>, preferring to do the treatment via code, since the paths are also all defined via code also.

  • It doesn’t end up being more complicated to have to work with Viewable and create a class to return html content? web.xml and regain a redirectTo() for the first or second page?

  • 1

    @Luizfilipe I usually do not use pure HTML but Jersey + Freemarker. Anyway, using a Servlet API Filter does not require working with Viewable.

  • even I know that it does not prevent, and you can be sure that Filter will be of great help, however my question is restricted in how to redirect between the pages that are in the configuration <welcome-files-list>

  • 1

    @Luizfilipe Hum... I don’t know if I understand what you want. O welcome-file-list is not a list of site pages, but a list of default file names when the user accesses a URL without specifying the page. Using the question example, if the user type /app/pasta in the URL, the server will search for index.html on the way /app/pasta/index.html (from the app folder). If it does not find this file, then the server will search for /app/pasta/login.html.

  • 1

    @Luizfilipe If I’m understanding correctly, you must specify only index.html in web.xml and, in checking in the filter if the user is not logged in, redirecting it to login.html. If the login is successfully executed, then you redirect the user to the index.html or simply to the application’s base folder. If the login form checks with an Submit for a Servlet, just redirect. If login is done via Ajax, then you can use window.location.href to redirect the user to the other page.

  • This is a good solution!

Show 1 more comment

Browser other questions tagged

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