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 7558035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:16:47+00:00 2026-05-30T12:16:47+00:00

I want to include a js file in my jsf page. i tried the

  • 0

I want to include a js file in my jsf page. i tried the usual way of doing it but it didnt work.

<script language="Javascript" type="text/javascript" src="js/alertMessages.js"></script>

I also tried the adf components as below: but there is no af:resource component in my adf lib.

<af:document>
  <f:facet name="metaContainer">
    <af:resource source="/mySourceDirectory"/>
  </facet>
  <af:form></af:form>
</af:document>

Please let me know how do i include the js file in my page.

Thanks…

  • 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-30T12:16:48+00:00Added an answer on May 30, 2026 at 12:16 pm

    Relative resource URLs (the URLs of <script>, <link>, <img> and <a> elements which do not start with scheme http:// or slash /) are relative to the current request URL (as you see in browser address bar).

    So if you’re for example opening the page by

    http://localhost:8080/contextname/somefolder/page.jsf

    then the script file as you have there will actually be downloaded from

    http://localhost:8080/contextname/somefolder/js/alertMessages.js

    instead of

    http://localhost:8080/contextname/js/alertMessages.js

    You would like to make the URL relative to the domain root instead. So it must become /contextname/js/alertMessages.js. You can use ${pageContext.request.contextPath} to inline the context path dynamically:

    <script type="text/javascript" src="${pageContext.request.contextPath}/js/alertMessages.js"></script>
    

    Note that the language attribute is superfluous. Also please note that for JSF 2.x there are tags available which do that implicitly like <h:outputScript>.

    See also:

    • Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
    • Is there something like <c:url> for JSF?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to include one html file into another, but it doesnt seem to
I want to include external js file in my php script. I am following
I want to include a file, whose name is in page.var . How can
I have a basic Node.js+socket.io app, and want to include coffee-script file. It was
I have a jsf page that contains some javascript includes. And I want to
I want to include a php file in a div box whenever one generated
I want to include a header file only if a certain function body is
I have a Java project and I want to include a text file with
i want someone to include a JS file of me which does something neat.
I want to include some dynamic part in the filename of the msi file

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.