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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:08:33+00:00 2026-06-16T02:08:33+00:00

I am using JSP on NetBeans. In the java code, I am trying to

  • 0

I am using JSP on NetBeans.

In the java code, I am trying to read data from a file. First I open the file by specifying its path.

Because my code runs on a server (GlassFish), I would like to have my file path independent of the machine where it runs. Therefore, I want to start the path with the folder name that contains the file which is saved on the root of the project directory. I tried so hard to achieve that but I couldn’t.

I read online and I found this way, but it still doesn’t work:

<%

  //building the tree here.
GraphBuilder tree = new GraphBuilder("${pageContext.request.contextPath}\\src\\java\\Database\\OptimizedFullTermFile.pad");

%>

Can anyone help? 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-06-16T02:08:35+00:00Added an answer on June 16, 2026 at 2:08 am

    Just read it from the classpath. Given that you’re using the typical src folder representing the Java source code (the Java package/class structure), I assume that the file OptimizedFullTermFile.pad is placed in the Java package java.Database (eek, a capital in package name? lowercase it all). In that case, it’s already in the classpath and thus you can just get it straight from there as follows:

    InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("java/Database/OptimizedFullTermFile.pad");
    // ...
    

    As to your failed attempt: the EL ${pageContext.request.contextPath} isn’t ever going to work in a scriptlet. Even if it did, it’s not the right thing, it returns the context path in the webapp URL which is absolutely not part of the local disk file system path, let alone the classpath. Using scriptlets is strongly discouraged since a decade, by the way.

    See also:

    • getResourceAsStream() vs FileInputStream
    • Where to place and how to read configuration resource files in servlet based application?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In doing JAVA based web projects using JSP in netbeans, under Web Pages folder
I want to iterate this set of code using jsp, (I'm using Netbeans 7.2.1)
In a web project using jsp, I have following requirement Upload a file (say
My web application is written using jsp/javascripts. Backend Java. Have managed to implement the
I'm using Netbeans 6.8 to develop application using JSP. I'm able to work with
I am working on JSP in Netbeans 7.0 and right now the jsp code
Why my file-upload code is not working? I am using commons-fileupload-1.1.1.jar. Also I am
i am using NetBeans, and i am working on a jsp page that allows
I am trying to dynamically generate content using JSP. I have a <c:forEach> loop
I'm doing a web project using jsp,mysql,ajax using netbeans and mysql. I'm having 3

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.