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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:58:04+00:00 2026-05-20T16:58:04+00:00

This is an error that came up after I got a previous question here

  • 0

This is an error that came up after I got a previous question here answered. Essentially I’m trying to bring the absPath of the folder with me so I can make some Files at runtime regardless of where my code is located. I was recommended to use

getServletContext().getRealPath("/");

To find the correct path.

I tried it in my JSP page, but I get an unterminated string literal right when I create the absPath variable. Here is the script I try to run.

<script type="text/javascript">
        var RemoteUserId = "<%=(request.getRemoteUser()==null)? "blah" : request.getRemoteUser()%>";
        var contextPath = "<%= request.getContextPath()%>";         
        var extPath = "<%=extPath%>";
        var absPath = "<%=getServletContext().getRealPath("/")%>";
        var env='<%=string1%>';
</script>

What am I missing? Do I have to escape the returned path name, or did I misinterpret when I was supposed to use this.

Edit**
This is what the source shows upon accessing the page
(slightly tweaked so I’m not showing my full C: path)

<script type="text/javascript">
        var RemoteUserId = "blah";
        var contextPath = "/TRACK";         
        var extPath = "http://xxx/sales/it/tlp/ext-3.2.1";
        var env='null';
        var absPath = "C:\Documents and Settings...\TRACK\";
</script>
  • 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-20T16:58:04+00:00Added an answer on May 20, 2026 at 4:58 pm

    Like as in Java, backslashes are escape characters in JS. You need to escape them to represent a literal backslash. In other words, your absPath variable must end up as

    var absPath = "C:\\Documents and Settings...\\TRACK\\";
    

    You could do this by

    var absPath = "<%=getServletContext().getRealPath("/").replace("\\", "\\\\")%>";
    

    But still, it makes no sense to me to pass a Java variable back to Java via JavaScript. Just access it in the Java side when the code is about to process the request. Imagine that you’re using a servlet to process the request, just do

    String absPath = getServletContext().getRealPath("/");
    

    instead of

    String absPath = request.getParameter("absPath");
    

    (or whatever you’re doing to get the absPath back in your Java code)

    Also note that all the JavaScript code is fully controllable/spoofable/hackable by the client. The client is able to edit JavaScript variables while the code is running. The client could for instance change the path before it is been used. Keep this in mind!

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

Sidebar

Related Questions

Today after deploying some changes to a C# MVC site that I run, I
I put together a test table for a error I recently came across. It
Currently I am trying to clone this git repo: https://github.com/twilio/OpenVBX into my main repo,
I seem to be in over my head. I have been trying to change
I've followed the directions here to build html documentation https://code.ros.org/trac/opencv/browser/trunk/opencv/doc/README.txt (actually my local copy
After (another) bout with Visual Studio slowness, I went into procmon to see if
I want to write generic method that checks if a given entity is in
Today I was reading up on debugging and I came across a post in
I can very well understand from this Selectutorial what element/tag based descendant selectors are,
My development machine died and I've had to rebuild it from scratch. I reinstalled

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.