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

I'm getting this error after trying to appendChild to an element that was just
I got this error when I tried to compile an application that includes the
I just got Java5 project that has this error, i tried using Java5 and
I am getting this error now that I hit version number 1.256.0: Error 4
I'm getting this error... What is puzzling me is the fact that i do
What are the most common reasons that I would be getting this error from
This is the error Dependency Walker gives me on an executable that I am
It's easy! I just came across this blog post by Rudi Grobler that says
I'm getting an error here that says I haven't defined a method, but it
This is beyond both making sense and my control. That being said here is

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.