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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:56:38+00:00 2026-05-15T23:56:38+00:00

How do you get the request URL in a bean backing a JSF page?

  • 0

How do you get the request URL in a bean backing a JSF page? I’ve been looking through the FacesContext docs and the best way I could find seems terribly long:

public String getRequestURL()
{
    Object request = FacesContext.getCurrentInstance().getExternalContext().getRequest();
    if(request instanceof HttpServletRequest)
    {
            return ((HttpServletRequest) request).getRequestURL().toString();
    }else
    {
        return "";
    }
}

Edit: Functional Requirements The requirement here is that we need the full URL for a third party javascript utility. The use or architecture of the utility doesn’t fit well with JSF, but everything short of this call does. The method I found will work, but it felt wrong to be digging so deep into the FacesContext. Additionally I was hoping there would be a way that could be called with JSF Expression Language since this is going to be used in a “view” related way.

  • 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-15T23:56:39+00:00Added an answer on May 15, 2026 at 11:56 pm

    If you ever need to haul the raw Servlet API from under the JSF hoods by the FacesContext, then chances are that you’re doing the job at the wrong place. What is it, the functional requirement for which you thought that this is the right solution? Should you maybe not be using a real Servlet class or a Filter instead of a JSF managed bean? Or maybe don’t you need the request URL at all because there are better “jsfish” ways to achieve the same?

    If you update your question to include the detail about the functional requirement, then we may be able to suggest the right solution.


    Update as per your edit: so, you just need it after all in the view side? E.g. #{bean.requestURL}? You can also just grab it from the HttpServletRequest object which is already implicitly available in EL.

    When you’re on JSP:

    ${pageContext.request.requestURL}
    

    Or when you’re on Facelets:

    #{request.requestURL}
    

    And now, how do you need it for JavaScript? Printing as a JavaScript variable? Like so?

    var url = '#{request.requestURL}';
    

    If so, you could also just grab window.location for that.

    var url = window.location;
    

    No need to clutter the JSF bean with the view specific details.

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

Sidebar

Related Questions

I want to get only the headers of an URL request. I have been
In my application , a HTTP GET request URL to the application with script
A simple get request made to url on my server which returns HTML of
I'm trying to URL encode a string to form a GET request from objective-c.
What is the maximum allowed size of a URL for a GET request in
I read that some webmail services prefetch url links in emails. The GET request
I have a very simple ajax request: $.get(url, data) .done(function () { }) .fail(function
I get BufferedReader from the following networking code. URL url = new URL(request); HttpURLConnection
I am executing an AJAX request using jQuery as such: $.get({ url: 'run_program.php', data:
I have an input in my jsf page like this <html:inputText id=ResponseOK value=#{bean.ResponseOK} binding=#{bean.ResponseOKInput}

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.