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

  • Home
  • SEARCH
  • 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 6194527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:18:39+00:00 2026-05-24T03:18:39+00:00

I have this structure: WebContent resources components top.xhtml company about_us.xhtml index.xhtml top.xhtml is a

  • 0

I have this structure:

WebContent
    resources
        components
            top.xhtml

    company
        about_us.xhtml

    index.xhtml

top.xhtml is a component, that is used in index.xthml and about_us.xhtml too.

top.xhtml

<ul>
    <li><a href="index.xhtml">Home</a></li>
    <li><a href="company/about_us.xhtml">About us</a></li>
    ...
</ul>

So my problem is, when the current page is index.xhtml the component generates URLs correctly, but when the current page is about_us.xhtml, it generates wrong URLs. I cannot use relative path because it’s going to generate the wrong URL too. I think it is because the component is based on the current path of the *.xhtml page.

The only solution I could found out is:

<ul>
    <li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
    <li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
    ...
</ul>

But I think is not ‘elegant’ at all. Any ideas?

  • 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-24T03:18:40+00:00Added an answer on May 24, 2026 at 3:18 am

    URLs are not resolved based on the file structure in the server side. URLs are resolved based on the real public web addresses of the resources in question. It’s namely the webbrowser who has got to invoke them, not the webserver.

    There are several ways to soften the pain:

    JSF EL offers a shorthand to ${pageContext.request} in flavor of #{request}:

    <li><a href="#{request.contextPath}/index.xhtml">Home</a></li>
    <li><a href="#{request.contextPath}/about_us.xhtml">About us</a></li>
    

    You can if necessary use <c:set> tag to make it yet shorter. Put it somewhere in the master template, it’ll be available to all pages:

    <c:set var="root" value="#{request.contextPath}/" />
    ...
    <li><a href="#{root}index.xhtml">Home</a></li>
    <li><a href="#{root}about_us.xhtml">About us</a></li>
    

    JSF 2.x offers the <h:link> which can take a view ID relative to the context root in outcome and it will append the context path and FacesServlet mapping automatically:

    <li><h:link value="Home" outcome="index" /></li>
    <li><h:link value="About us" outcome="about_us" /></li>
    

    HTML offers the <base> tag which makes all relative URLs in the document relative to this base. You could make use of it. Put it in the <h:head>.

    <base href="#{request.requestURL.substring(0, request.requestURL.length() - request.requestURI.length())}#{request.contextPath}/" />
    ...
    <li><a href="index.xhtml">Home</a></li>
    <li><a href="about_us.xhtml">About us</a></li>
    

    (note: this requires EL 2.2, otherwise you’d better use JSTL fn:substring(), see also this answer)

    This should end up in the generated HTML something like as

    <base href="http://example.com/webname/" />
    

    Note that the <base> tag has a caveat: it makes all jump anchors in the page like <a href="#top"> relative to it as well! See also Is it recommended to use the <base> html tag? In JSF you could solve it like <a href="#{request.requestURI}#top">top</a> or <h:link value="top" fragment="top" />.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this menu structure that is used to navigate through content slider panels.
Given that I have this resultset structure (superfluous fields have been stripped) Id |
I have a project created in Eclipse that has roughly this structure: src conf
I have this XML structure that I wish to construct in JSON format using
i will try to explain the problem. I have this structure: offers -------------- id_offer|offer|company
I have this structure on form, <input type=test value= id=username /> <span class=input-value>John Smith</span>
I have this HTML structure and want to convert it to an accordion. <div
I have this HTML structure (excerpt): <td> <select id=test1 class=pub_chooser> <option value=99>All Publications</option> <option
I have this table structure and would like to map it using Fluent Hibernate
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add 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.