Reading a file in the same directory as the JSP files

Hi,
Okay so I have my JSP files in the directory $Catalina/webapps/webservices, I also have a text fire in the same directory called users.txt
All I want to do is open the users.txt from the JSP program and read from it. But JSP can't seem to find the users.txt.
Code I have tried include,
File users = new File("users.txt");
File users = new File("http://localhost:8080/webservcies/users.txt"); Also File users = new File(new URI ("http://localhost:8080/webservcies/users.txt"));
File users = new File("webservices/users.txt");
I guess part of the problem is that I don't know what the JSP working directory is. I assumed it was $Cataline/work/standalone/localhost/webservices
but even if I use,
File users = new File("../../../../webapps/webservices/users.txt");
It doesn't work. Does anyone know how I can read the file? Any help in this matter would be appreciated.

From within a JSP you have a reference to a PageContext called pageContext. This has a method getServletContext(). From the ServletContext you can find the real path the servlet lives in. So...
File basePath = new File(pageContext.getServletContext().getRealPath("/"));Now basePath contains your path $Catalina/webapps/webservices. Then it's just a matter of working relative to that, e.g.:
File usersFile = new File(basePath, "users.txt");

Similar Messages

  • How to keep the servlet java code the JSP engine generated?

    Hello there!
              I am using some JSP in a web application, and would like to take a llok
              at the servlet java files th weblogic JSP engine generated.
              In my weblogic.properties file I have the following line:
              "# Set up WebLogic JSP properties
              weblogic.httpd.register.*.jsp=weblogic.servlet.JSPServlet
              weblogic.httpd.initArgs.*.jsp=\
              pageCheckSeconds=1,\
              compileCommand=F:/VisualCafeEE/bin/sj.exe,\
              workingDir=F:/weblogic/myserver/classfiles,\
              verbose=true,\
              keepgenerated=true"
              However, the only things I can find are the class files compiled from
              the servlet java files.
              Any suggestions?
              Thanks.
              Jeff.
              

    Moerover, if you follow the example web.xml Weblogic provides
              (http://www.weblogic.com/docs51/classdocs/sample_web_xml.html), the parser
              would complaint big time.
              The <servlet> and <context-param> tags have to be switched.
              Jeff
              "John J. Feigal" wrote:
              > I'm not sure why, but specifying keepgenerated=true in weblogic.properties
              > did not do the job for us.
              >
              > We had to add the following to our application's web.xml file:
              >
              > <!-- keepgenerated initArg to JSPServlet -->
              > <context-param>
              > <param-name>weblogic.jsp.keepgenerated</param-name>
              > <param-value>true</param-value>
              > </context-param>
              >
              > --
              > John J. Feigal Voice (651)766-8787 (main)
              > Sr. Technical Consultant (651)766-7249 (direct)
              > Ensodex, Inc. Fax (651)766-8792
              > 4105 N. Lexington Ave., Suite 150 email [email protected]
              > Arden Hills, MN 55126 WebSite http://www.ensodex.com
              >
              > "Jong Lee" <[email protected]> wrote in message
              > news:[email protected]...
              > >
              > > You have the init arg "keepgenerated" tunred on in weblogic.properties.
              > > The java file should be kept in the same directory of your jsp file.
              > >
              > > You can also use "jspc" to generate the java source.
              > > i.e:
              > > "java weblogic.jspc -keepgenerated yourjspfile"
              > >
              > >
              > >
              > >
              > >
              > > Jeff Wang <[email protected]> wrote:
              > > >Hello there!
              > > >
              > > >I am using some JSP in a web application, and would like to take a llok
              > > >at the servlet java files th weblogic JSP engine generated.
              > > >
              > > >In my weblogic.properties file I have the following line:
              > > >
              > > >"# Set up WebLogic JSP properties
              > > >weblogic.httpd.register.*.jsp=weblogic.servlet.JSPServlet
              > > >weblogic.httpd.initArgs.*.jsp=\
              > > > pageCheckSeconds=1,\
              > > > compileCommand=F:/VisualCafeEE/bin/sj.exe,\
              > > > workingDir=F:/weblogic/myserver/classfiles,\
              > > > verbose=true,\
              > > > keepgenerated=true"
              > > >
              > > >However, the only things I can find are the class files compiled from
              > > >the servlet java files.
              > > >
              > > >Any suggestions?
              > > >
              > > >Thanks.
              > > >
              > > >Jeff.
              > > >
              > >
              

  • How to Save XML file in the same directory as the swf file automatically?

    Hi all,
    I'm really new here with flash and actionscript 3, so i might not make any sense, probably. Any input is greatly appreciated.
    So here's my problem, i'm trying to make a Top Score history for a flash game, which i load from an XML file. The problem comes to when i want to update the XML file. how do i do that automatically without prompting the user (ofcourse). I want it to be saved automatically to the same directory as the flash file.
    here's my code right now, but it prompts the user where it wants to be saved, which i don't want to happen:
    var xml:XML = <XML>
                        <topScoreList>
                        </topScoreList>
                  </XML>;
    for(var i:Number=0; i<10; i++)
         var Record:XML = <Record>
                             <score></score>
                             <playerName></playerName>
                        </Record>;
         Record.score.appendChild(topScores[i].toString()); //topScores[] -> class variable containing scores
         Record.playerName.appendChild(topNames[i].toString()); //topNames[] -> class variable containing names
         xml.topScoreList.appendChild(Record);
    var ba:ByteArray = new ByteArray();
    ba.writeUTFBytes(xml);
    var fr:FileReference = new FileReference();
    fr.save(ba, "topScoreList.xml");

    yeah that makes sense, actually - after reading a dozen more forums. It's really weird tho that flash doesn't have a Buffer writer, unlike other programming frameworks.
    But yeah, thanks. i'll start reading on flash.net.SharedObject, correct ? Thanks.
    Anyways, if anyone out there has a different input, will be greatly appreciated!!

  • Accessing a file not in the same directory

    I would like to get the first line of a txt file and perform certain analysis on it, I can do this when the file is located in the same directory but i'm experiencing problems when it comes to trying to get a file outside of my current folder .
    What do I need to do when I recieve the string from the user containing the directory and name of the file (e.g. C:\Test\file.txt).
    Any help would be appreciated

    refer following code.
    String path = "C:\\Test\\file.txt";
                   BufferedReader reader = new BufferedReader(new FileReader(new File(path)));
                   System.out.println(reader.readLine());     

  • Does a wrapper html file need to be in the same directory? Need advice

    I'm doing some RnD experiments for an upcoming project and I would like to use Edge.
    What I'm trying to do is load 2 different compsites in a wrapper.html file that is level above the compsites. For instance my setup is
    project/wrapper.html
    project/product1/product1.html
    project/product2/product2.html
    In my wrapper file I have this, but this doesn't work
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
        <title>Untitled</title>
    <!--Adobe Edge Runtime-->
        <script type="text/javascript" charset="utf-8" src="product1/product1_edgePreload.js"></script>
        <style>
            .edgeLoad-EDGE-68005601 { visibility:hidden; }
        </style>
    <!--Adobe Edge Runtime End-->
    </head>
    <body style="margin:0;padding:0;">
        <div id="Stage" class="EDGE-68005601">
        </div>
    </body>
    </html>
    But when I move the wrapper.html file into the same directory as product1 and modify .js path and it loads fine? So my question is how do people normally load multiple compsites that resided in a different directory? What is the best method for accomplishing this? If anyone can point me in the right direction please. Thanks in advance.

    You will need to update the new loction for even the product1_edge.js file and the product1_edgeActions.js file in the product1_edgePreload.js file.
    Open up the product1.edgePreload.js file.
    Search for 'aloader'.
    Under this there should be a ' load: "product1_edge.js" '  change it to  ' load: "product1/product1_edge.js" '
    and do the same for product1_edgeActions.js file too.
    Bascially when you update the location of the edge preload file you will have to update the location of the animate assets like the edge file,edge actions,images etc.All these file locations work relative to the html file loading them.

  • When Opening a file in TextWrangler it defaults to the same directory

    When i open a file in textwrangler and a couple of other applications it defaults to the same directory each time. Normally it will remember the last opened directory.
    This was only an issue when i upgraded to Snow Leopard from Leopard.
    Does anyone know if there is something that can be done to fix this issue.

    See this:
    [http://support.mozilla.com/en-US/kb/Changing+the+e-mail+program+used+by+Firefox]

  • Jar file is not working after deleting all packages from the same directory

    hello
    i have created a jar file named as server.jar in the same directory in which i have all the packages(for which i have created this jar file).This jar file was working correctly when i had all the packages in the same directory.But after deleting all the packages from the same working directory, this jar file is neither working nor giving any error message..
    Please tell me what may be the reason???
    thanks in advanced

    hello
    i have created a jar file named as server.jar in the same directory in which i have all the packages(for which i have created this jar file).This jar file was working correctly when i had all the packages in the same directory.But after deleting all the packages from the same working directory, this jar file is neither working nor giving any error message..
    Please tell me what may be the reason???
    thanks in advanced

  • I cannot open Firefox as I get the message that Firefox failed to read configuration file. I uninstalled and reinstalled latest version and still cannot open with the same error.

    Last week when the automated upgrade came I said yes and then stopped it midway as it was not a good time to reboot my laptop. Since then, when I try to open it says cannot read configuration file - even when I uninstall and reinstall - still cannot open it with the same error.

    Do a clean (re-)install:
    * Download a fresh Firefox copy and save the file to the desktop.
    * Firefox 4.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Uninstall your current Firefox version and remove the Firefox program folder before installing that copy of the Firefox installer.
    * Do not remove personal data if you uninstall the current version.
    * It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    Your bookmarks and other profile data are stored elsewhere (not in the Firefox program folder) and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.

  • Is is possible to read a file while writing the same file at time in java?

    Hi ,
    I am reading a MSAccess file (mdb) from one location to another location .but the source file is an online database which will chage regularly .so while reading that file i am getting error like
    FileNotFoundException.
    java.io.FileNotFoundException: c:\Msaccess\db2.mdb (The process cannot access the file because it is being used by another
    s)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:106)
    at read.main(read.java:16)

    alphabet soup,
    Yes, windows helpfully prevents two processes from accessing a file simultaneously. Operating Systems on the other hand uniformly support it.
    Which probably doesn't help you very much, as I imagine that you can't just up and change the source machine over to *nix, but there you have it.
    You'll just have to close the program which has the database open, copy the database, and restart the program which uses the database.
    keith.
    Message was edited by: corlettk

  • Read form file ok, try to write to same file : FileNotFound

    My application starts reads an xml file. When I try to write back to the XML file I get
    javax.xml.transform.TransformerException: java.io.FileNotFoundException: file:\C:\Documents%20and%20Settings\alzoid\My%20Documents\Netbeans%20Projects\Laptop\UserSettings.xml (The filename, directory name, or volume label syntax is incorrect)
    I did SOP for file.getAbsolutePath() before it read and writes and the ouput is the same:
    "C:\Documents and Settings\alzoid\My Documents\Netbeans Projects\Laptop\UserSettings.xml"
    Here is the code that reads (works):
    public void fillToFile() {
            xmlFile = new File(TO_FILE_NAME);
            try {
                if(xmlFile.exists()) {
                    setToPocketPC(db.parse(xmlFile));
                } else {
                    createToPocketPC();
            } catch (SAXException se) {
                       se.printStackTrace();  
            } catch (IOException ioe) {
                ioe.printStackTrace();
        }Here is the code that throws the exception:
    private void writeDocumentToFile(Document doc,String fileName){
           try {
            xmlFile = new File(fileName);  
            System.out.println(xmlFile.getAbsolutePath());
            source = new DOMSource(doc);
            result = new StreamResult(xmlFile);
            transformer.transform(source, result); //fails here
            xmlFile = null;
            source = null;
            result = null;
           } catch (TransformerConfigurationException tce) {
               tce.printStackTrace();
           } catch (TransformerException te) {
               te.printStackTrace();
           } /*catch (IOException ioe) {
               ioe.printStackTrace();
        }The strange thing is I tested the read/write last week and it worked. I did not change any code. If I copy the file:\c:\Documents%20and%20Settings.... Path into windows explorer it finds the file.
    Any suggestions?
    Thanks
    Al

    I'm not sure why either, though the API docs mention "takes File to populate a StreamResult", which really does not make any sense. The File would be populated by the StreamResult. The way it is written would only make sense, at least to me, if the File was being used as input.
    Glad I could help. Best of luck.
    - Saish

  • Stop Lightroom from forcing "-edit" rename and saving in the same directory when saved from Photoshop

    After opening a file from Lightroom 5 in photoshop, is there a way to disable the function that automatically saves a file back to Lightroom in the same folder, while adding the infuriating "-edit" to the filename? I keep my files in a very tight file structure, with DNGs, PSDs, and JPGs all neatly separated. It drives me batty that when I save a file it saves it in the same directory as the DNG. Why would anyone want this as a feature. STOP IT!
    I know I can simply "Save As" but there has to be a way to turn this off.

    I know you can have Lightroom change the appended "-edit" (via Preferences) to practically anything you'd like but as far as I know, it's all by design. Photoshop/Lightroom will always save a copy and leave your original files alone. To be honest, I'd want all my edits contained to where the original file was as well. As long as they're in the same folder, I'm happy.

  • Copying files from same directory as *.java files and moving to WEB-INF/classes/ package name

    In our current application we have the following source directory structure:
              src -
              - com
              - edeploy
              - subdirs ... (many directories here)
              - jsp
              -subdirs ... (many directories here)
              In com.edeploy.subdirs, there exists *.java files, and *.gxq files (query
              files). I would like to modify my build.cmd script to copy the *.gxq files
              into the same directory as the class files.
              Here's my script so far:
              @REM Create list of files to compile
              DIR /S /B /A:-D src\com\*.java >class.list
              @REM Create list of query files
              DIR /S /B /A:-D src\com\*.gxq >query.list
              @REM Compile
              javac -d stage\WEB-INF\classes @class.list
              @REM Copy query files into class directory
              .......... code needed here ......
              Can anyone help me with this?
              Thanks,
              Matt
              

    You may want to check out:
              http://jakarta.apache.org/ant/index.html
              Gary
              "Matt Raible" <[email protected]> wrote in message
              news:[email protected]..
              > In our current application we have the following source directory
              structure:
              >
              > src -
              > - com
              > - edeploy
              > - subdirs ... (many directories here)
              > - jsp
              > -subdirs ... (many directories here)
              >
              >
              > In com.edeploy.subdirs, there exists *.java files, and *.gxq files (query
              > files). I would like to modify my build.cmd script to copy the *.gxq
              files
              > into the same directory as the class files.
              >
              > Here's my script so far:
              >
              > @REM Create list of files to compile
              > DIR /S /B /A:-D src\com\*.java >class.list
              >
              > @REM Create list of query files
              > DIR /S /B /A:-D src\com\*.gxq >query.list
              >
              > @REM Compile
              > javac -d stage\WEB-INF\classes @class.list
              >
              > @REM Copy query files into class directory
              > .......... code needed here ......
              >
              > Can anyone help me with this?
              >
              > Thanks,
              >
              > Matt
              >
              >
              

  • I have read 118 files (from a directory) each with 2088 data and put them into a 2 D array with 2cols and 246384row, I want to have aeach file on a separate columns with 2088 rows

    I have read 118 files from a directory using the list.vi. Each file has 2 cols with 2088rows. Now I have the data in a 2 D array with 2cols and 246384rows (118files * 2088rows). However I want to put each file in the same array but each file in separate columns. then I would have 236 columns (2cols for each of the 118 files) by 2088 rows. thank you very much in advance.

    Hiya,
    here's a couple of .vi's that might help out. I've taken a minimum manipulation approach by using replace array subset, and I'm not bothering to strip out the 1D array before inserting it. Instead I flip the array of filenames, and from this fill in the end 2-D array from the right, overwriting the column that will eventually become the "X" data values (same for each file) and appear on the right.
    The second .vi is a sub.vi I posted elsewhere on the discussion group to get the number of lines in a file. If you're sure that you know the number of data points is always going to be 2088, then replace this sub vi with a constant to speed up the program. (by about 2 seconds!)
    I've also updated the .vi to work as a sub.vi if you wa
    nt it to, complete with error handling.
    Hope this helps.
    S.
    // it takes almost no time to rate an answer
    Attachments:
    read_files_updated.vi ‏81 KB
    Num_Lines_in_File.vi ‏62 KB

  • FTP Adapter to read multiple files from a directory. Not through polling.

    Dear Friends,
    I would like to know is it possible to configure the FTP adapter in Oracle BPEL 10.1.3.4 to read multiple files (different names, same structure) from a given directory. I do not want the BPEL to do a polling. Instead when I submit the BPEL process it should read all files from the directory.
    I was looking at the option of Synchronous read but I am not able to specify wild card in the file name field. I do not know the file names at the time of reading.
    Thanks for your help!

    Hi,
    While you read the file, you can configure an adapter property in 'Receive'. This will store the filename, this filename can be used for sync read as the input parameter.
    1. Create a message type variable called 'fileheader'. This should be of type Inboundheader_msg (whatever relevant Receive activity).
    2. This variable will contain three parts - filename, FTPhost, FTPPort
    3. Copy this fileheader to 'Syncheader'.
    4. syncheader can be passed as an adapter proerty during sync read of the file.
    During Receive and Invoke, you need to navigate to 'Adapter' tab to choose the created message type variable.
    Let me know if you have further questions.
    regards,
    Rev

  • How do I read properties file kept in the source folder in weblogic workshop

    I want to have a log.properties file in the folder of the source java code which
    is reading this properties file. When I build the code the properties file also
    should go with the generated .class files.
    I am using class.getResourceAsStream("log.properties")
    I tries different ways to make the class to read the file, but it failed to find
    the properties file. Is there any way to keep the configuration files in the same
    directory of the source java code ? This is the problem of weblogic workshop 8.1.
    This thing runs fine in Tomcat.

    Did you try and add the path where the .properties file is located in the CLASSPATH?

Maybe you are looking for

  • I'd like to know if Windows 8 supports iTunes.

    I got a brand new iPod for Christmas and now my birthday is coming up and I'm getting a new computer. The computer I'm getting has Windows 8 on it. I'm hearing some people say that Windows 8 doesn't support iTunes and I really want to be sure whether

  • Adobe App Manager installs but won't work... "Download Error, Contact Support"

    Downloaded the AAM through the creative cloud site, it installs and when run it shows this error message "Download Error, Contact Support."  I then downloaded the AAM as a package from Adobe support.  Before installing it I removed the previous insta

  • What program should I be using?

    Hello friends, I am wanting to make a 3-5 sec video clip taken portion of a movie that I have on my HD and email it to a friend. I figured I could do this in iMovie, yet the file will not import. The original format was MPEG-1. I read that iMovie wou

  • How to get Leave Accrual Balance in Report

    We can see the accrual balance on SSHR page as well as on Fastpath-> Accruals -> Net Entitlement. But I want to display a report which will display all accruals as on a aprticular date. Can we get that? Is there any seeded funnction/procedure?

  • Script for font managment

    I often get a file created with the Indesign Package function. The fonts are in the Fonts folder and I have to create a shortcut in the Indesign Fonts Folder, for the Fonts not to be missing. So I created a Script that adds this shortcut var fontFold