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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:33:05+00:00 2026-05-30T18:33:05+00:00

Here is my question, I am using jsp script, trying to match a key

  • 0

Here is my question, I am using jsp script, trying to match a key word in requesting url and do something:

    <script>
     $url = '${pageContext.request.requestURL}';

    if("${fn:contains(url, 'key')}" == true){
        ...
    }
....

But this doest work… I am not sure where the problem is but I want it to be like when url contains this string, go in to the if condition.

Thank you

  • 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-30T18:33:07+00:00Added an answer on May 30, 2026 at 6:33 pm

    You are mixing JSP/EL and JavaScript as if they run in sync. This is wrong. JSP/EL runs in webserver and produces HTML code which get executed in webbrowser. JavaScript (JS) is part of the generated HTML code and runs in webbrowser only.

    You need to do it either fully in JSP/EL, or fully in JavaScript. You can use JSP/EL to dynamically generate JS code which get later executed when the page arrives at browser. Rightclick page in browser, do View Source to see what JSP/EL has generated. You should not see any line of JSP/EL. You should only see HTML/JS code. It’s exactly that JS code which get executed then.

    You’re using a JSP EL function to test a JS variable which isn’t in the variable scope at that moment at all. This is not going to work. It can only test JSP/EL variables.

    Here’s how you could do it in pure JS:

    <script>
        var url = window.location.href;
    
        if (url.indexOf('key') > -1) {
           // ...
        }
    </script>
    

    If you really insist in doing it using JSP/EL, you could do as follows:

    <script>
        var url = '${pageContext.request.requestURI}';
    
        if (${fn:contains(pageContext.request.requestURI, 'key')}) {
           // ...
        }
    </script>
    

    This will then generate the following JS code (rightclick page in browser and View Source to see it):

    <script>
        var url = '/some/uri';
    
        if (true) {
           // ...
        }
    </script>
    

    But this makes no sense. Whatever functional requirement you need to solve, you need to think twice about the right approach. Feel free to ask a new question about solving the concrete functional requirement the proper way.

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

Sidebar

Related Questions

So I decided to start using prototype and here's my first question. I'm trying
First question here. I am trying to instantiate a generic class using the type
I asked a question here : When To Use IEquatable And Why about using
Here's my question. Right now I have a Linux server application (written using C++
I'm using lucene in my project. Here is my question: should I use lucene
Despite an earlier question ( asked here ), our project is constrained to using
For more info, see my other question, here . So anyway, I'm using BigDecimals
I am working on a J2EE web application Here we are using JSP and
ím trying to add jstl/jsp component to a spring+flex+hibernate project. Im using Tomcat 5,
I have just added a linked library to my project using the question here

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.