Directory listing for a directory within the webapplication

Hi,
I have a the code which does the directory listing of a given directory using its absolute path. eg new File("c:/webapp/tempdir");).
I want to do the directory listing by giving a path relative to the context path of the webapp like(new File("/temp");)
When I try to do
<%
File f1=new File("/tempDir");
f1.exists(); --> returns flase
%>
tempDir is a directory in my webapplication. How should I reference this? Should I have to use file:// or http://?
Looking forward for your help
Thanks in advance

There is a method in ServletContext: getRealPath.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html
It turns a website relative path into a real location on disk.
// only need this line in a servlet.  "application" is already defined in a jsp
ServletContext application = getServletConfig().getServletContext();
String filePath = application.getRealPath("/tempDir");
File f1 = new File(filePath);Some issues with using this approach:
If your application is in an unexploded WAR file, then getRealPath() can return null, as there isn't really a location on disk that it relates to.

Similar Messages

  • Directory lister for the web.

    Hi
    Here iam attaching my project code for my particualr aplication
    The source code for a directory lister for the web. You give it
    one or more URLs as arguments and its not displays the formatted results .. can any body will help me
    import java.util.*;
    import java.net.*;
    import java.io.*;
    public class WebList extends abcd.Application
    static final String progName = "WebList";
    public static void main( String[] args )
    (new WebList()).compat( args );
    public int newMain( String[] args )
    int argc = args.length;
    if ( argc == 0 )
    usage();
    return -1;
    for ( int argn = 0; argn < argc; argn++ )
    if ( argc > 1 )
    if ( argn > 0 )
    out.println( "" );
    out.println( args[argn] + ":" );
    list( args[argn] );
    return 0;
    private void usage()
    err.println( "usage: " + progName + " URL ..." );
    void list( String urlStr )
    String base = abcd.Utils.baseUrlStr( urlStr );
    Enumeration as;
    try
    as = new abcd.Spider( urlStr, err );
    catch ( MalformedURLException e )
    err.println( e );
    return;
    while ( as.hasMoreElements() )
    URLConnection uc = as.nextElement();
    if ( uc == null )
    continue;
    URL thisUrl = uc.getURL();
    String thisUrlStr = thisUrl.toExternalForm();
    if ( thisUrlStr.startsWith( base ) )
    thisUrlStr = thisUrlStr.substring( base.length() );
    if ( thisUrlStr.length() == 0 )
    thisUrlStr = ".";
    String mimeType = uc.getContentType();
    int len = uc.getContentLength();
    long mod = uc.getLastModified();
    Date modDate = new Date( mod );
    String modDateStr = abcd.Utils.lsDateStr( modDate );
    out.println(
    abcd.Fmt.fmt( mimeType, 14, abcd.Fmt.LJ ) + " " +
    abcd.Fmt.fmt( len, 8 ) + " " +
    modDateStr + " " + thisUrlStr );
    try
    InputStream in = uc.getInputStream();
    in.close();
    catch ( IOException e ) {}
    }

    Hi,
    It is enumerating the files reachable at or
    below those URLs, i hope it will full fill your application requirements.
    and also in the for loop you have to do pre increment not post increment so it may be the casue for entier your logic ..
    as per my knowledge iam changing the code .. i hope it will work for your application...
    still if you have any querys please post me with details of your projects so that i can help you more..
    here is modified code:
    =================
    import java.util.*;
    import java.net.*;
    import java.io.*;
    public class WebList extends abcd.Application
    static final String progName = "WebList";
    public static void main( String[] args )
    (new WebList()).compat( args );
    public int newMain( String[] args )
    int argc = args.length;
    if ( argc == 0 )
    usage();
    return -1;
    for ( int argn = 0; argn < argc; ++argn )
    if ( argc > 1 )
    if ( argn > 0 )
    out.println( "" );
    out.println( args[argn] + ":" );
    list( args[argn] );
    return 0;
    private void usage()
    err.println( "usage: " + progName + " URL ..." );
    void list( String urlStr )
    String base = abcd.Utils.baseUrlStr( urlStr );
    Enumeration as;
    try
    as = new abcd.Spider( urlStr, err );
    catch ( MalformedURLException e )
    err.println( e );
    return;
    while ( as.hasMoreElements() )
    URLConnection uc = (URLConnection) as.nextElement();
    if ( uc == null )
    continue;
    URL thisUrl = uc.getURL();
    String thisUrlStr = thisUrl.toExternalForm();
    if ( thisUrlStr.startsWith( base ) )
    thisUrlStr = thisUrlStr.substring( base.length() );
    if ( thisUrlStr.length() == 0 )
    thisUrlStr = ".";
    String mimeType = uc.getContentType();
    int len = uc.getContentLength();
    long mod = uc.getLastModified();
    Date modDate = new Date( mod );
    String modDateStr = abcd.Utils.lsDateStr( modDate );
    out.println(
    abcd.Fmt.fmt( mimeType, 14, abcd.Fmt.LJ ) + " " +
    abcd.Fmt.fmt( len, 8 ) + " " +
    modDateStr + " " + thisUrlStr );
    try
    InputStream in = uc.getInputStream();
    in.close();
    catch ( IOException e ) {}
    Regards,
    TirumalaRao.
    Developer Technical support,
    sun MicroSystem, India.

  • How to disable the Directory listing for the whole server or a particular a

    Please let me know how to disable the Directory listing for the whole server or a particular application.
    Thank You

    I want to disable the tab focusing( tab index) for a JTextField objectsLook through the API and find methods with the word "focus" in the method name.
    Also can u tell me about how to change the tab index orders for JTextFields."How to Use the Focus Sub System":
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html

  • Delivery without reference for stock transfer within the same plant 311

    Dear all,
    I need to create a delivery without reference for stock transfer within the same plant, movement 311,  i.e. just from 1 storage location to another storage location.
    I tried to use VL01NO with delivery type UL.
    Now my question is how can I assign a receiving plant for a customer?
    I can't do the MIGO or MB1B document because I need the delivery document (packing list, forms, Texts,...).
    It's possible this option???
    Thank you very much.

    Hi,
    What is the item category you are assigning while doing VL01NO?  Check the schedule line category for that item category assignment.  That Schedule line category has an option for one step GI.  There you can assign 311 or create a separate item category and schedule line category and in that SC assign 311. 
    Thanks
    Krish.

  • To set a dropdown list for one column in the excel file before downloading

    Hi all,
    I am downloading an excel file which has the format of an internal table with a number of fields. I want to set a dropdown list for one column in the excel file. How can i do this?
    Thanks

    HI ,
    U can use function module " QINT_GET_EXCEL_DATA " ....
    and modify the excel sheet based on ur requirement ......
    Try this ...
    Hope it works
    Thanks
    Shambhu

  • Lion Server: How can I enable directory listing for the Web Server?

    The functionality was part of the Server App in Lion Server but was not included in Lion.  Can anyone shed some light on how to enable Directory Listing.  Any help is appreciated!

    Go to /etc/apache2 and edit the file 000_any_80_.conf
    using sudo nano command and replace  "-Indexes" with "+Indexes".
    Restart Apache with "sudo apachecrl restart"
    Good luck,
    Ricky
    from Costa Rica

  • SSO for various applications within the same portal

    Is it possible to implement SSO at the application level in an EP 7.0 environment?
    Ex:  One Portal with ESS and BI Functionality (BI is connected to the BI backend, ESS is connected to the ECC backend, but all of it exists within the same portal instance) in which the BI Explorer would rely on SSO, while the ESS would require a logon to the portal.  The initial page of the portal would not be a logon screen, but rather a menu screen
    Does this functionality exist?

    For our purposes, ESS would have to be authenticated (perferably through Active Directory), while BI Explorer wouldn't require "visible" authentication, BUT the question would be, could all of this exist on the same portal..
    I agree that it certainly wouldn't be user friendly to ask users to logon (using AD l/p) for certain parts but not others.  I think the solution would simply to have 2 portal instances (ESS/ECC = Logon/Password,  BI Portal = SSO), and to federate the BI to the ECC Portal. That way, if someone wanted to work in BI and only BI, they could go without logging on, but if they wanted to go to the ESS Portal they would have to logon BUT would be able to use both ESS and BI.
    This all stems from an effort to eliminate the neccessity of having to logon to a portal (for a small group of managers), but still maintaining a level of security for ALL users in regards to employee self-service

  • Advice needed for changing code within the Web IC...

    Hi,
    I need to change some code within the GET_QUERY_RESULT Method, which is found:
    BSP->Z_CRM_IC
    View->AuiSearch
    Controller class ZL_CRM_IC_AuiSearch_impl
    Method do_handle_event
    Method eh_onsearch
    Method get_query_result
    At present the method get_query_result belongs to class CL_CRM_AUI_QUERY_SERVICE.
    I can create a subclass from this and call it ZL_CRM_AUI_QUERY_SERVIC, then redefine the method get_query_class, and then make the appropriate changes. But that may be all uneccessary. What I don't know is how to ensure this modified code can be called.
    I have already made changes for method DO_INIT_CONTEXT, hence the reason the controller class ZL_CRM_IC_AUISEARCH_IMPL is identified. But this was simple because the view linked directly to this whereas you can see the code I need to change is further down in process chain.
    I know that method get_query_result calls a number of BADI's, but these BADI's are too low for the information that I need and therfore really need to make my code changes in the get_query_result method.
    I have been reading as much as I can on this subject, but without much success and therefore really count on experienced developers like yourselves to steer me in the right direction, or give advice.
    Jas

    I will not suggest to put your Enhancements into CL_CRM_AUI_QUERY_SERVICE.
    Rather in  Component BT  -> Class CL_CRM_BTIL .  AUi Query Service will Internally call the BOL Component ( get query result )
    In your Framework Profile Config  , you specify the Component Set  . Ex: ALL
    Component set have a List of Component Ex BP , BT .
      SPRO-> CRM -> CRM Cross Application Components -> Generic Interaction layer -> Basic Settings
    Now you can have your Custom , Component Set ( Ex : ZALL ) and Component ( ( Ex ; ZBT , Totally advisable for CIC Development Framework )
    Have BT Copied into ZBT and  Specify  ZL_CRM_BTIL (  Inherited from CL_CRM_BTIL )
    And in your Custom Component Set , Specify ZBT instead of BT . 
    Now Specify your Custom Component Set in your Framework Profile .
    Now you got the Enhancement Spot in  ZL_CRM_BTIL->GET_QUERY_RESULT
    Let me know if it make sense

  • Search a Directory Tree For a Directory

    Hello All,
    Alright, the backround first. I am working on a system for managing photos for cases. So, the top photos dir has 5 dirs represnting the years. In each of those, are months, in those are days, and in the days there are dir named for the casenumber. This may sound confussing but...Say for Case number 05-00001 which happened January 1st 2005, the photos would be in ./photos/2005/1/1/05-00001/Now I cant change the dir structure because this is how the system uploads them, but I need a program to search this dir tree when the person enters a case number and return the photos. Everything works great (from a logic standpoint) but the problem is that there are about 20,000+ cases a year and if the case is toward the end it takes FOREVER to search through them all.
    What I am looking for is suggestions on how to most efficently search for these cases...
    Thanks,
    Matt

    a particular string. I was able to read one file in
    a single directory but not in any other directory.
    How would I go about writing code to be able to
    access all files in directory that has multiple sub
    folders.
    You can do that several ways.
    Most likely you'll end up with some sort of recursive iteration over the directory tree.
    Not hard to write, somewhat harder to prevent memory problems if you end up with a lot of data.
    Also, when I started to write my program I tried to
    use the DOM XML Parser to parse my html page. My
    logic behind this decision was that if you look at
    html code it is an xml document. But as I was
    trying to run my program I noticed that I had to
    convert my html document into xml format. I really
    don't want to have to build my own html parser. Is
    there a html parser that is included in Java. Oh my
    program is just your basic text program. No
    interfaces.
    A VALID xhtml document is a valid XML document.
    Problem is that most HTML isn't xhtml.
    Another problem is that most HTML is fundamentally broken even to its own standards (which have always been based on SGML on which XML is also based).
    Browsers take that into account by being extremely lax on standards compliance and effectively making up tags as they go along to fill in the missing ones in the trees they parse.
    That's however not a standardised process and each browser handles it differently (and as a result most html will render differently in different browsers).
    Java contains a simple HTML parser in Swing, but it's primitive and will only parse a subset of HTML 2.0.
    There are almost certainly 3rd party libraries out there that can do better, both free and/or commercial.

  • Materia transfer Procedure for asset  material within the plant

    Hi
    We need to set the process in SAP for asset material transfer from onle location to another within the plant and also send back defective one back to vendor.
    Please suggest the procedure to do the same SAP.
    Regards
    venkat
    Edited by: garapati on Feb 29, 2008 6:35 AM

    hi,
    clarify that material code is used or not.
    if material code is used then use 301 mov type.
    regards
    points if solved/helpful
    Edited by: RAMESH ARORA on Feb 29, 2008 12:04 PM

  • Due list for invoice is showing the S1 canceled documents

    Due list for invoice list (VF24) is showing the documents which are S1 billing type
    how can we restrict the S1 canceled documents in due list for invoice list
    Thanks and Regards
    Kishroe

    Hello,
    if you never want S1 documents in invoice list, then run VOFA and clear the field 'Invoice list type'.
    In this way S1 documents are not relevant for Invoice list.
    To update th Invoice list status of existing S1 documents, see the SAP note[ 1078149|https://bosap-support.wdf.sap.corp/sap/support/notes/1078149].
    Best regards,
    Ivano.

  • Dreamweaver CS5 for Mac - Files within the whole panel minimize

    I'm working in Dreamweaver CS5 for Mac.  Dreamweaver is active and open with the Panel open with files, CSS styles etc tabs open.  I want to add an image to the my Image folder within the Files tab.  Well when I click the Finder icon, it takes focus off Dreamweaver and then the Panel disappears.  This makes it difficult to add pictures to my current site I'm working on.  Then when I click the Dreamweaver screen again this Panel reappears.
    Is there a setting to keep this whole Panel from minimizing or disappearing when Dreamweaver is not on focus?
    Thank you.
    CC

    Assuming you have defined a LOCAL SITE within DW, use INSERT > IMAGE (browse to the image on your local HD or DW Local Site folder)
    If image is not already in the DW Local Site Folder, you will get a prompt to copy the image there. Hit YES and tell DW where to put the image within your local site.
    Or maybe I'm missing something....
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • On secound shippment list for pre orders on the evo 4g

    i pre orderd my evo 4g on may 26th 2010 after doing so i was told i was on secound list for the secound shippment when is that going to happen cuz rs said i could get one on the 4th should i return my pre oreder and goto radio shake not knoking bb theve ben my fav store for years buy whats the sence of a preorder if your not going to get it on launch day thanks
    Solved!
    Go to Solution.

    The cutoff for launch day was 5-21. Since you preordered after that, you preordered for the second shipment which arrives on 6-9. You did have more than two weeks to preorder for the first shipment.

  • How do I create a group list for email contacts with the I pad ?

    How do I create a group contacts with the iPad ?

    If you set up groups in iCloud, a contact can also belong to multiple groups. And no work around or mispurposing of a field needed. You can also filter a group without using the search function. Plus, your contacts are backed and available via another avenue if needed.
    Not questioning your solution - I'm sure it works - but the functionality exists within the design.

  • Can I have two seperate iTunes lists for two iPods on the same computer?

    I have two nanos, one for me and one for my daughter. Can we manage two seperate download lists when we plug in to the same computer.
    The additional complication...her nano has a smaller memory than mine, so her's wouldn't hold all the songs anyway.
    Assistance would be appreciated!
    Happy holidays
    Nordic Squirrel

    Have a look at this article in the Apple Knowledge Base.

Maybe you are looking for

  • How to overwrite styles with CSS?

    I have a large number of older html documents (I use Dreamweaver CS3 Premium) that were originally built using "regular" styles. I have tried to overwrite these old styles with CSS but this doesn't work. I first delete the old styles, attach the CSS

  • Having trouble with including JNI library in netbeans

    [Sorry a newbie question - I am more used to writing large amounts of Solaris kernel and writing a JNI for the first time] Guys, I have a C library that needs to hook into the Java bean. I created a JNI library wrapper around the C library using swig

  • Reports not running in Infoview

    I just migrated some reports from our Dev server to Test Server. The reports in Test Infoview do not run,. How ever I am able to run them in Crystal designer. This did not happen in the past when ever I migrated the reports. Any suggestions on what c

  • Safari displaying AAAA

    Hi I've updated to Yosemite and now certain internet sites are displaying AAAAAAAA. I believe this is probably a font cache issue, but I'm not  very technically minded so I'm not sure how to resolve it

  • How to share resume via pages to online job search

    I've been trying to post resume to online job applications.  Not having much success.  New iPad user