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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:48:49+00:00 2026-05-20T12:48:49+00:00

Can someone test this example and share the results? http://timothypowell.net/blog/?p=23 When I do: var

  • 0

Can someone test this example and share the results?
http://timothypowell.net/blog/?p=23
When I do:

var myVar = '<% request.getContextPath(); %>';
alert(myVar);

I get : '<% request.getContextPath(); %>'.

Removing the enclosing single quotes from ‘<% request.getContextPath(); %>’;
gives syntax error.
How can I use the scrptlet or expresion inside a js function?

EDIT: this link has an explanation that helped me:
http://www.codingforums.com/showthread.php?t=172082

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

    It sounds like you are placing the JSP code within a JavaScript page, or at least in a non-JSP page. Scriptlets can only be included in a JSP page (typically configured to be *.jsp).

    The statement as presented, if processed by the JSP compiler, would result in myVar being equal to ” as the scriptlet format you are using <% … %> executes Java code between the tags, but does not return a result.

    So, to use this tag you would need to manually write a value to the request output stream. To get the desired functionality you need to do the following:

      make sure your code is in a JSP page
      use var myVar = '<%= request.getContextPath() %>'; (note the equals sign)
    

    With all that said, scriptlets are viewed as bad practice in most cases. For most cases, your should be using JSTL expressions and custom tags.

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

Sidebar

Related Questions

Can someone tell me why this unit test that checks for exceptions fails? Obviously
Can someone explain this result to me. The first test succeeds but the second
Can someone show me a working example of how this world be achieved? I'm
Can someone explain why the HashMap acts like it does in this example: Simple
Can someone explain to me why the following works for the first test but
Can someone please explain what the & does in the following: class TEST {
Can someone give an example of a good time to actually use unsafe and
Can someone provide an example were casting a pointer from one type to another
OK, I've not been able to figure this out thus far. Hoping someone can
Can someone explain how egg-info directories are tied to their respective modules? For example,

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.