Current directory in a webapp

Hi,
Are there any functions by which i can get the path where my webapps jsps reside or the classes my webapp uses.
e.g.
in the webapps/mywebapp has my web application. is there a get function which will retrieve the path.
I have a file in this path i am trying to open (i keep getting java.io.FileNotFoundException )
looks like it doesnt understand the path.
Thank you

In ServletContext class...
java.lang.String getRealPath(java.lang.String path)
Returns a String containing the real path for a given virtual path.

Similar Messages

  • How to get the path of current directory?

    I have the Java servlet to produce text file, and it produces to C:\hello.txt,
    but I want to output in the current directory as the Java File:
    i.e. C:\jakarta-tomcat-4.1.30\webapps\ExtendedGUI\WEB-INF\classes
    try
         PrintWriter out = new PrintWriter(new FileWriter("hello.txt"));
         out.println("HELLO");
         out.close();
    catch(IOException e)
    any ideas?? Thanks!!

    The current directory is defined as the directory that you started your servlet container from. In your case, it was c:\. If you want it to fall into the same directory as your class files, I would start by finding out what TOMCAT_HOME or whatever container you're using is and adding to the directory until you get to your class directory. Make sense?
    The easiest way is to read the output directory from a properties file as a resource or a hardcoded path.
    HTH

  • Running a java program in a directory other than the current directory

    How do I run a java program that's located in a directory other than the current directory?
    There is a file Test.java in /dir1/subdir1. If my current directory is anywhere other than that directory, say /dir2/subdir2, I can compile Test.java by using:
    javac -classpath /dir1/subdir1 /dir1/subdir1/Test.java
    But when I try to run it with:
    java -classpath /dir1/subdir1 /dir1/subdir1/Test
    I get a java.lang.NoClassDefFoundError: \dir1\subdir1\Test
    Any thoughts?

    You need to specify just the name of the class you want to run. So java -classpath /dir1/subdir1 Test

  • How to trace an application which is not in the current directory?

    Hi,
    When I use simple example 'Trace' to trace my application in current directory, it works well.
    But I cannot trace the applications which are in different directory or in an .jar file. Even I've already add it to the classpath.
    The following is my test:
    I put Myapp.class in .\classes
    java -cp .;.\classes com.sun.tools.example.trace.Trace Myappit shows me:
    java.lang.NoClassDefFoundError: Myapp
    Warning: classic VM not supported; client VM will be used
    Exception in thread "main" -- VM Started --
    -- The application exited --Can anyone help me ?
    thanks

    The following is my test:
    I put Myapp.class in .\classes
    java -cp .;.\classescom.sun.tools.example.trace.Trace MyappThere are two JVMs involved when you are tracing or debugging.
    Rather than putting the classpath on your command line, set it as
    an environment variable so that both JVMs can use it. That way, the
    second JVM (which is executing the Myapp class) will be able to find it.
    If your current directory is %JAVA_HOME%/demp/jpda, then this example
    will trace the SwingSet2 demo program:
    set CLASSPATH=".;%JAVA_HOME%/lib/tools.jar;%JAVA_HOME%/demo/jfc/SwingSet2/SwingSet2.jar"
    java com.sun.tools.example.trace.Trace SwingSet2Let me deconstruct the CLASSPATH:
    . is on the classpath so the first JVM will locate
    the com.sun.tools.example.trace.Trace class relative to
    your current directory. You may also use the absolute
    path instead of dot.
    %JAVA_HOME%/lib/tools.jar is there so both JVMs
    can locate the JDI (Java Debug Interface) classes in tools.jar.
    %JAVA_HOME%/demo/jfc/SwingSet2/SwingSet2.jar is
    there so the second JVM (the debugee) can load the
    SwingSet2 class..

  • Getting current directory from an applet

    Hi. How can I get the current directory of my applet running on web without having to worry about permissin. I used the one below:
    curDir = System.getProperty("user.dir");
    but I get this error:
    ava.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
    any substiture for this? Thanks.

    You should be using URLs or similar approaches, and avoiding File, which will
    never work with an ordinary applet.
    InputStream in = this.getClass().getResourceAsStream("file.txt");That assumes the txt file is in the same place as the current classes .class file.
    For example, the same folder or that they are jarred in the same "folder" in the jar.
    You can also use a URL directly:
    URL url = ...
    InputStream in = url.openStream();and you can construct that URL with the help of Applet methods getDocumentBase or getCodeBase:
    URL url = new URL(this.getDocumentBase(), "file.txt");That assumes the txt file is in the same folder as the html file in which the applet is embedded.

  • How can I make an applet look to the current directory to read a txt file in?

    I am using a File class passing only the file name as the contructor but forte still looks in "C:\forte_jdk\forte4j\bin\Events.txt" which is not my current directory for the project.
    If leave it and ftp this applet to my web site I get an IOException.

    I always find visual aids helpful. See below for screenshots & discriptions.
    01. The Basics
    When you create a new site & go into design view (in the example below it's the Home page), you'll see the following.
    The white box is your page.
    The grey box outside of that is your browser area.
    The black & white checkered area is the Adobe Muse CC application chrome.
    02. Add Box
    Draw / Add your rectangle or text frame (text tool). I drew a rectangle, gave it a fill color of blue & turned the stroke from 1 to 0.
    03. Extend & Snap to Browser Edge (Left)
    Click, hold  and drag your mouse on the center adorner (adorner is the little squares that you can grab to resize your rectangle) until you resize your rectangle to the browser edge (the dark grey area) until you see a red line. This means you've 'snapped' one of the rectangle's edge to the browser edge.
    04. Extend & Snap to Browser Edge (Right)
    Repeat the process except do this for the right edge. In truth, it doesn't matter in which order you resize your rectangle to snap to the browser edges. The key thing is to be sure to do this for both sides of the rectangle & snap it to the browser edge (see the red line).
    05. You're done! Preview.
    06. Bonus!
    Once again, you can make rectangles or text frames 100% width, BUT you can't do this with placed images.
    However, you can do this with a rectangle or text frame. Then set the Fill of either the rectangle & text frame to be an Image & set the Fitting to 'Scale to Fill.'
    (see below for example - I used a rectangle & changed it's Fill property)
    Now when I preview, the image is 100% width. In truth, it's a 100% width rectangle with a fill of an image.

  • How to create a file in current directory

    hi,
    I want to create a file in a current directory, But when i written following
    code then it cannot create file, How i will create file in current directory?
    Is there anyone who can help me?what will be the solution of this problem?
    Please give me solution
    String dir=application.getRealPath("/");
         int count;
         String filename="sample.txt";
         out.println(dir+filename);
         FileOutputStream fout=new FileOutputStream(filename);
         PrintStream p;
         p=new PrintStream(fout);
         p.print("1");
         p.close();with regards
    Bina

    hi,
    my problem is that my path is ok...but when i open file in this directory then
    it cannot open a file, is there anyone who can do it? When a user save data in server from remote
    area then what will be path of my code? how i will solve it? please give me
    solution.
    with regards
    bina

  • Acrobat Pro "save as" function in the file menu does not show the current directory of the file

    I have installed CC but Acrobat Pro gives me headaches.
    The "save as" function in the file menu does not show the current directory of the file but something I have worked on in the past.
    It forces me to navigates through my hard disk for this very straightforward thing in normal conditions. I precise: Acrobat is the only software reacting like that.
    I use Windows7 professional 64bits.

    I use what seems to be the latest version available on the Cloud:
    To illustrate my point, I open a directory with explorer and double-click on the only PDF in there:
    So here it is, open:
    When I do a "Save as", it takes me to a totally different place on the disk!
    Very annoying...
    Thanks for your time!
    JJ

  • How to get absolute path of current directory?

    Hi, everyone!
    I want to get the absolute path of current directory.
    Are there some APIs that I can use?
    Thanks in advance,
    George

    Hi, dheeraj_tak buddie!
    What do you mean in your reply?
    "in File class u have all this methods for getting absolute path "regards,
    George

  • Specifying current directory in Receiver File Adapter

    Hi Experts,
    I have been configuring a receiver file adapter to place a file onto an FTP server. As per the information provided, as soon as I login to the FTP server, I have to place the file in current logged in directory. In this case, how can I mention this in file adapter as to use the current directory path to place the file? What should I enter in 'Target Directory' in File Access Parameters?
    Thanks,
    Dhawal

    Hi Praveen,
    Since file directory parameter is mandatory, my question is what should I enter in this parameter so that the file adapter will know that the file should be placed in the root directory itself?
    Regards,
    Dhawal

  • How to read files from current directory for applet

    I have an applet that needs to read some audio files located in its current directory on the server and I just can't seem to figure it out...maybe I am being dumb...any help?

    You can use the ListSorter File Adapter Configuration property to sort based on timestamp. Basically add the following property to the inbound JCA file:
    <property name="ListSorter"
    value="oracle.tip.adapter.file.inbound.listing.TimestampSorterAscending"/>
    <property name="SingleThreadModel" value="true"/>
    More info see section 4.2.6 in http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm

  • E-mailing report attempts to write temp file in current directory

    When e-mailing a report from the previewer, Reports 6.0 attempts to write a temporary file in the current NT directory. This file is the actual e-mail attachment, in this case a PDF file.
    Unfortunately the current directory is where the application resides, and therefore users do not have write permission. Is there any way to re-direct where the temporary file is created (i.e. a local drive or the Windows temp directory)?
    Thanks in advance.

    change your registry key entry which says
    REPORTS60_TMP to which ever dir you want

  • How to create a file in server's current directory

    hi,
    I have a project, but when i will run my program on internet Explorer then
    it will create a folder in server's current directory, but i will not specify
    drive & folder, it will create a folder in server's current directory, after that
    i will read file from that, what will be the solution of this ? Is there
    anyone who can give me solution? PLease help me
    With regards
    Nahar

    ServletContext context = session.getServletContext();
    String realContextPath = context.getRealPath(request.getContextPath());this will give you access to the servlets current directory
    from there you can create a file
    I dont know how much this will help

  • Create folder in current directory

    Hi all,
    I would like to be able to create a folder through my java program, in the current directory that the java program is in.
    Furthermore, I do not want to have to change any code if the java program is suddenly moved to a different folder.
    Something like this, but obviously currentDirectory would have to actually be the specific directory that the program is in:File f = new File(currentDirectory);
    f.mkDir();Also, just on a side note if anyone has any knowledge of MySQL, I would like to be able to do this when using 'batch mode' and pointing a batch file to a text file containing mysql commands:
    mysql -u root -p < d:\mysql\jdbc\createdatabase.txtso the current directory would replace 'd:\mysql\jdbc\'.
    thanks very much

    Hi Jon
    On the first topic, try this.
    import java.io.File;
    public class MakeDir {
         public static void main(String[] args) {
              if (args.length != 1 || args[0] == null || args[0].trim().length() == 0) {
                   System.out.println("Usage: java MakeDir <folder name>");
                   System.exit(-1);
              File f = new File(System.getProperty("user.dir") + "\\" + args[0]);
              f.mkdir();
    }/John

  • Specify current directory of file?

    hey I'm trying to get a file but the only way it works when i program is if i give the full path, like
    ApplicationContext ctx = new FileSystemXmlApplicationContext("C:\\olddata\\Documents and Settings\\Space\\Projects\\Testing\\BeanTest\\src\\context.xml");how do i just tell Eclipse to get context.xml from the current directory?
    I tried,
    ApplicationContext ctx = new FileSystemXmlApplicationContext(".\\context.xml");
    ApplicationContext ctx = new FileSystemXmlApplicationContext("context.xml");but it just gives me FileNotFoundException
    Thanks

    after a lil trial and error i got it,
    ApplicationContext ctx = new FileSystemXmlApplicationContext(".\\src\\context.xml");
    .\\context.xml only referred to the project folder so i was forgetting src folder in which
    context.xml was located

Maybe you are looking for

  • Outlook 2013 Constantly Prompting For Credentials - Exchange 2007 - Small Business Server 2008

    Hello, I am having a problem using Windows Small Business Server 2008 and Exchange 2007 with Outlook 2013. The issue is that a credentials box appears in Outlook 2013 when using there exchange account whilst connected to the domain. The box will rand

  • Relocating SOFFCONT1 items to external content server

    I've read the other forum threads on this subject but am still having issues with program RSIRPIRL.  Regardless of which Document Area I choose in the selection criteria screen, I cannot seem to locate any of the SOFFCONT1 documents.  I can't use PHI

  • Moving playlists from iPhone or iPad into iTunes

    Is there a good solution to move my playlists from either my iPhone or iPad into iTunes? I backed up to computer but I see that it only backed up purchased music.

  • Problem window.opener.doSubmit

    Hello, We have one application, say with URL http://localhost/some_app This is not an APEX application. On this application on click of a button we popup an APEX page (with public access) and when user clicks on "Ok" button of this APEX page we pop t

  • Captivate 4 movie in RoboHelp 7 causes crash in Topic Preview

    Hello all, I was running a RH7 HTML course last Friday. They have used Captivate 4 to create an on-screen demo movie. We inserted this movie into a topic and did a Preview: all OK, looks fine. Then, when we closed the preview, it crashed RoboHelp. Th