Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:08+00:00 2026-05-27T15:56:08+00:00

In a JSF application, we have the directory hierarchy: webapp xhtml login.xhtml main.xhtml search.xhtml

  • 0

In a JSF application, we have the directory hierarchy:

webapp
  xhtml
    login.xhtml
    main.xhtml
    search.xhtml
  css
    main.css
    extra.css
  js
    jquery.js

etc. The servlet mapping is:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

This works fine, but the URLs of our web app look like this:

http://localhost/myapp/xhtml/login.xhtml
http://localhost/myapp/xhtml/search.xhtml

We would like to have simpler URLs by dropping the /xhtml part, i.e.
http://localhost/myapp/login.xhtml

I could not find any way to accomplish this. Is there some way to do this in the <servlet-mapping>? Do I need some additional framework?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:56:09+00:00Added an answer on May 27, 2026 at 3:56 pm

    You could do it with a Filter. Either homegrown or a 3rd party one like URLRewriteFilter. Just map it on *.xhtml and then forward to /xhtml/*.

    Something like:

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    
    String ctx = request.getContextPath();
    String uri = request.getRequestURI();
    String viewId = uri.substring(ctx.length(), uri.length());
    
    if (viewId.startsWith("/xhtml")) {
        // Redirect to URL without /xhtml (changes URL in browser address bar).
        response.setStatus(301);
        response.setHeader("Location", ctx + viewId.substring("/xhtml".length());
        // Don't use response.sendRedirect() as it does a temporary redirect (302).
    } else {
        // Forward to the real location (doesn't change URL in browser address bar).
        request.getRequestDispatcher("/xhtml" + viewId).forward(request, response);
    }
    

    But simpler would be to just change the directory hierarchy to get rid of /xhtml subfolder. Those CSS/JS (and image) files should preferably be placed in a /resources subfolder so that you can utilize the powers of <h:outputStylesheet>, <h:outputScript> and <h:graphicImage> in a proper way.

    See also:

    • How to reference CSS / JS / image resource in Facelets template?
    • Structure for multiple JSF projects with shared code
    • Should I use URLs as links to images and other resources or should I use the EL #{resource…}
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok simple question. I have a JSF application, containing a login page. The problem
I have a simple JSF application, a search form and results table, and a
I have a JSF application that uses mostly Richfaces. I would like to introduce
I have a JSF application with several major components and a component tree under
I am new to JSF and have a problem with my simple JSF application.
i have a JSF web application. I use Beans as Spring Beans (not JSF
I have a Java-JSF Web Application on GlassFish, in which I want to use
I have some problem's with a simple application in JSF 2.0. I try to
I'm using JSF 1.2 with Richfaces and Facelets. I have an application with many
I have a small JSF application where the user is required to enter some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.