Finding files via the servlet container.

We are currently developing a web application on Tomcat. We have several XML files that are deployed with our application which are parsed on startup. Currently we do this by retrieving the InputStream of each file via the ContextClassLoader:
Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);I would like to have the application crawl a given directory (and sub all sub directories) and read each XML file rather than specifying the path of each file. Is there a way to do this via the container? It seems there is no way to do this via the ContextClassLoader.
We are able accomplish this using the Java IO package and absolute paths. Is there a reason (besides portability) that we should not load these files via the Java IO package functionality? I would prefer to use the web container for portability reasons. We will eventually port this to other application servers and I am wondering if the behavior is consistent across them.
Message was edited by:
abug

But remember to keep in mind that you may get a null if you're deploying your app as a .war ( or in any other case where the container cannot give you the real path ).

Similar Messages

  • How to find the servlet container used via servlet

    I need to write code for different servlet container in a servlet. so I need to find in runtime what servlet container is used.
    Please let me know is there any possibility to get the servlet container name in servlet.
    Thanks & Regards,
    Nasrin.N

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class Context extends HttpServlet {
    public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
    PrintWriter out=res.getWriter();
    res.setContentType("text/html");
    ServletContext stx=getServletContext();
    out.println("ServletContext " + stx.getServerInfo());
    }

  • How do I save and find files on the ipad?

    How do I save and find files on the iPad?

    Files/documents need to be stored/associated within an app on the iPad, unlike 'normal' computers there is no file system which allows you to save files with no means of being able to read/use them. So if you want to store a file on the iPad you first need an app on the iPad that supports that file type.
    How you then get the file onto the iPad and into the app will depend on what the app is and what transfer method(s) it supports. e.g. some apps use the file sharing section at the bottom of the device's apps tab when connected to your computer's iTunes, some apps support the transfer of files via your wifi network, the iBooks app uses the Books section of your iTunes (and the device's Books tab) to sync content, and other transfer methods include email attachments, Dropbox etc. The file is then found by going into your chosen app and opening/using the file.

  • How to get list of jar files loaded by servlet container.

    Hi,
    I need to display in my servlet program about the list of jar files loaded by servlet container. Does it vary for each servlet container or is it same. Where can I get those details.
    I need to write code to support tomcat 4x, iplanet 5.0 and websphere 6.0.
    Thanks & Regards,
    Nasrin.N

    For curious, here are output prints for all 3 methods:
    1) parsing system property
    2) tschodt
    3) overcast SystemClassLoader to URLClassLoader
    /home/espinosa/workspace/jboss_embedded_test1/target/test-classes
    /home/espinosa/workspace/jboss_embedded_test1/target/classes
    /opt/javalibs/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
    /opt/javalibs/javax/jms/jms/1.1/jms-1.1.jar
    /opt/javalibs/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar
    package com.sun.org.apache.xerces.internal.impl.validation, Java Platform API Specification, version 1.6
    package com.thoughtworks.qdox.directorywalker
    package com.sun.org.apache.xerces.internal.parsers, Java Platform API Specification, version 1.6
    package java.util.jar, Java Platform API Specification, version 1.6
    package org.testng.internal.thread
    package com.sun.org.apache.xerces.internal.util, Java Platform API Specification, version 1.6
    package java.net, Java Platform API Specification, version 1.6
    package sun.reflect.misc, Java Platform API Specification, version 1.6
    package esp.ejb.samples1.test
    package sun.security.provider, Java Platform API Specification, version 1.
    file:/home/espinosa/workspace/jboss_embedded_test1/target/test-classes/
    file:/home/espinosa/workspace/jboss_embedded_test1/target/classes/
    file:/opt/javalibs/javax/ejb/ejb-api/3.0/ejb-api-3.0.jar
    file:/opt/javalibs/javax/jms/jms/1.1/jms-1.1.jar
    file:/opt/javalibs/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar
    ...Interestingly, method 1 and 3 gives the same list, same order, same count, just format of item is a little bit different. The order is same as in Eclipse .classpath file.
    Method 2 (tschodt) give significantly more items! rougly 3x! Different order (somewhat random it seems to me). Some items contain extra information, like version and string "Java Platform API Specification".
    It prints not absolute paths but logical Java names.

  • Visual Studio 2013. Viewing a PDF file via the Web Browser control in Windows 8.1

    I am writing a Windows Forms application in which I need to view PDF files via the Web Browser control. When the control is given the Navigate() command, Windows takes over and asks which program I want to open the file with. All was fine with VS 2010 and
    XP. I have un-installed "PDF Complete", which was the default PDF viewer, but I now get asked for an alternative.
    Thanks in advance.
    Mike Saunders

    Hi Mike,
    It seems that we could use Internet Explorer to open a local .PDF file if it has the Adobe Reader. I doubt that the web control would be related to it. Like the MVP's suggset in the following thread, maybe it would be related
    to certain plug-in tools in your side like the adober reader.
    Reference:
    https://social.msdn.microsoft.com/Forums/en-US/a717117e-41ae-4775-9c28-d5a1042b396e/pdf-is-not-opening-in-web-browser-control-in-vbnet?forum=vbgeneral
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Why can't i import AVCHD files via the Media browser?

    Why can't i import AVCHD files via the Media browser ? (Right click on the AVCHD file and imported, got the "format not supported" message.) I can import through the File-Import way  ( I can get down tot he BDMV folder and mts files) but read using the Media Browser is the preferred way.

    No you need the private folder. This will open in the Browser.
    Dont open just click.

  • How do I transfer files via the thunderbolt cable

    How do I transfer files via the thunderbolt cable. 

    Like you would with any other cable. What are you connecting together?

  • Using normal class file in the servlet

    Hello Friends;
    Now my problem is ;
    I generated a java file ;
    import drasys.or.mp.*;
    import drasys.or.mp.lp.*;
    public class optimize
        public static void main(String[] args)
        try
            int r=1;
            int s=0;
    .This file works perfect. It calls an API and there is no problem. But when I take this code into my servlet, then problem starts. First it says;
    "java.lang.NoClassDefFoundError: drasys/or/mp/ScaleException"
    but I know it is there. And I mounted the jar file.
    Do you think there is a problem with my codes, because it works when it is outside of the servlet.
    My servlet code is as follows;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.net.*;
    import drasys.or.mp.*;
    import drasys.or.mp.lp.*;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
             try
            int r=1;
            int s=0;
            int n = 3;
            int t,w,u,v,f;
            f = 1;
            int z=0;
            int y = 1;
            int l = 1;
            double [][][][] C = new double [1][1][n-1][n];
            double [][][][] D = new double [1][1][n-1][n];
            C[0][0][0][1]=2.5-0.92*r;
            C[0][0][0][2]=1.43-0.37*r;
            C[0][0][1][2]=1.14-0.48*r;
            D[0][0][0][1]=0.65*r+0.94;
            D[0][0][0][2]=0.31*r+0.75;
            D[0][0][1][2]=0.27*r+0.40;
         SizableProblemI prob = new Problem(n*(n-1)+1,n);
            prob.getMetadata().put("lp.isMaximize", "true");
            prob.newVariable("Lambda").setObjectiveCoefficient(1.0);
            for (t=0;t<=(n-1);t++)
                prob.newVariable("W"+t).setObjectiveCoefficient(0);
            final byte LTE = Constraint.LESS;
            final byte EQU = Constraint.EQUAL;
            for (v = 1;v <= n*(n-1);v++)
                   prob.newConstraint("constr"+v).setType(LTE).setRightHandSide(y);
                prob.newConstraint("constr"+(n*(n-1)+1)).setType(EQU).setRightHandSide(1);
                // here, we are creating coefficients for lambda.
            for (u = 1; u <= n*(n-1); u++)
                    prob.setCoefficientAt("constr"+u,"Lambda",y);
    // here, we are creating coefficients for W�s.
            for(t = 0 ; t <= (n-2); t++)
                for (w = 1; w <= (n-1); w++)
                     if (t<w)
                         prob.setCoefficientAt("constr"+l, "W"+t, 1);
                         prob.setCoefficientAt("constr"+l,"W"+w, (-C[s][z][t][w]));
                         l = l + 1;
                         prob.setCoefficientAt("constr"+l, "W"+t, -1.0);
                         prob.setCoefficientAt("constr"+l, "W"+w, D[s][z][t][w]);
                         l = l + 1;
    /* here , we are creating coefficients for the last formula which is w1+w2+w3+....Wn = 1 */
                for (f=0; f <= (n-1); f++)
                prob.setCoefficientAt("constr"+(n*(n-1)+1), "W"+f, 1);
    /* API finds the solution below.*/
         LinearProgrammingI lp = new DenseSimplex(prob);
            double ans = lp.solve();
            System.out.println("Solution"+r+"="+ans);
            System.out.println(lp.getSolution());
            catch (drasys.or.mp.DuplicateException first)
             first.getMessage();
            catch (drasys.or.mp.NotFoundException second)
            catch (drasys.or.mp.InvalidException third)
            catch (drasys.or.mp.NoSolutionException fourth)
            catch (drasys.or.mp.UnboundedException fifth)
            catch (drasys.or.mp.InfeasibleException sixth)
            catch (drasys.or.mp.ConvergenceException seventh)
            catch (drasys.or.mp.ScaleException eigth)
               eigth.toString();
       

    Thanks a lot for the reply.
    Forgive me, I have no object oriented background,
    even programming. I am just in the learning phase.This is a pretty advanced problem to tackle for your first programming task.
    That's why it doesn't follow OO concepts. This part
    will be connected to user input part, that I've
    completed .Hmmm.
    Successful programming depends on one idea: "divide and conquer". You take a big problem and solve it by dividing it into smaller chunks that you CAN handle. You get the solution you want by bringing the smaller chunks together.
    In your case I'd recommend that you get the optimization code into a single object that you can test off-line, without Tomcat. It looks like you started to do that with your optimize class, but the mistake you made is to put so much code into the main() method. You can only call that on the command line. Better to encapsulate the rest of it into small methods that will let you instantiate an instance of optimize and call its methods. Once you have that working you can wrap it in a servlet if you want to use it in a Web app.
    Separate how your optimizer gets its data from how it processes it. On a desktop app, it might be convenient to read input from a file on disk. A Web app might be better served by an XML stream.
    Why I said "I know it is there" because it doesn't
    give any other error message than that one, if it
    couldn't see the jar file, wouldn't it give me lots
    of error messages? Don't assume anything. It only needs one error, which is the one you get when it can't find a class. How many more do you need? The class loader couldn't find that class, so it printed the message and stopped.
    "I mounted" the jar file means I'm using Netbeans, I
    mounted it to that environment as suggested by
    Netbeans, If you don't know Java or programming well, I'm guessing that you also don't know NetBeans. I'd recommend that you figure out how to make all this work without NetBeans before you add another complication to your life.
    If you don't use NetBeans, all you have to do is add the JAR to your CLASSPATH using the -classpath option on javac.exe when you compile and java.exe when you execute.
    Tomcat assumes that all the JAR files in your Web app's WEB-INF/lib are in the CLASSPATH. If you put it in there, Tomcat will find it.
    you're right, I'm using Tomcat 5.0,
    everything is working fine, user input servlets,
    mysql connection etc. Only this part is causing the
    problem now.If you've already got a Web app deployed and connected to MySQL, you're not doing too badly. Kudos to you - that's not too bad for someone who claims to be a programming novice.
    I'll put that jar file into lib folder as you suggested thanks.I think that might be all you'll need. Try it and see.
    Actually I saw an example it was using "throws
    exception" , I couldn't figure out where to put it,
    and I decided to get rid of the compiling errors just
    putting bunch of catch statements.If you're saying that your code is throwing a lot of checked exceptions, and you added these extra catch blocks to get rid of them, another way to do it would be to simply have a single catch block, like this:
    try
        // your code in here
    catch (Exception e)
        e.printStackTrace();
    }Polymorphism says that this catch block will handle all checked exceptions.
    >
    Looks like I don't know anything but I'm trying to
    handle a big thing :))).Indeed you are. Anyone who can write a Web app and connect it to a relational database on their first try is hardly helpless. We're all ignorant, just about different things. Keep digging - you'll make this work.
    But thank you soooo much for your detailed answer, and happy new year.
    Shamil.And the same to you, Shamil. Good luck, and let me know how you make out.
    %

  • Blank PNG Files in the ePub3 container are to large for publication in the Apple iBookstore

    Hello i need your help - asap
    Fix layout ePub3 export from ID
    ID: newest version
    Siteformat: IPad Standard
    Export: for IPAD
    Picture format: PNG 150dpi
    largest pictures in my publication are 1536x2048 pix
    After uploading the ebook to the apple store i will have the ERROR ITMS-9000 - Images to large - more than 3,200,00 pixels are not allowed.
    So - i locked into the ePub-container and there are so many blank png-files - with a file format of 1600x2144 pix
    That the same size of the images of my book when I export it as JPG-Files.
    Cant find the Error in my document.
    The name of the blank mpg-files are 234.png / 2341.png / 23410.png etc.
    how can help?
    all the best
    Friedhelm

    Adobe i thing you have a problem. - But i thing also my problem is that i used ID for the JOB.
    Here the first result of a short test.
    clear ID-Doc iPAD format 768 x 1024
    placed a small square on a blank page.
    Export as FIX ePub3 with PNG 150dpi.
    rename the pub-file and extracted it
    found 2 PNGs in OEBPS/image/
    my black square als 221.PNG 180x180 pix and a PNG file called 206.png with the square in the middle and this file has1600 x 2133 pix 
    So i did a job to create and bild up an ebook with more than 80 pages - work more than 5 days on the project - and now this!
    I can´t publish the ebook to the itunes store.
    Not a happy about this.

  • None of the links in my TOC or INDEX work. Cannot find file is the error message.

    The files are on a networked drive. Win7. FM 8. I've renamed files. Regenerated. Created a new book. Nothing works.
    I do have hyphens and underscores in the file names but no other special characters.
    Need help urgently.
    The error message is:
    Cannot find file named
      \SOL\Data\TechDocs\DRAFT\Shiva\OperatorManual\096-0461-001C-1.
                 fm.
                 Make sure that the file exists.
    Note that the TOC and INDEX are listed in the book w/o a path while the body chapter has the entire path (above) listed in the book view.
    Thanks

    IIRC, FM8 had an issue with a path having more than 5 (or 6?) sub-folders. Try bringing the files up a few levels or create a mapped network drive down to the lower levels.

  • Downloading a pdf file, saving it, won't show the full name of the saving file when the name contains a space, stopping the file name.

    Downloading a pdf file, the name of the file contains a space in the middle of the file. The name showing on the 'Save' popup is the first few letters up to the space. Works fine on IE8. For instance, a file named "old snail_12345.pdf" would only show "old" (ignore the "s). This is on Firefox 30.0, WinXP Pro.

    Is this a problem when you are viewing the file in Firefox's built-in PDF Viewer and using its download button, or when you are using a download button in a web page?
    I've seen this problem occur when the server is pushing a different file name than the actual file name (for example, the file name is pdf.asp?id=12345 but the server is sending the name Annual Report.pdf in the headers sent with the file). I'm not aware of a workaround for the user, but for what it's worth, it is easy to fix on the server by replacing the spaces with %20 (the standard substitution used in web addresses).

  • Can I locate an .InDD file via the Folio Builder?

    Hi everyone! With InDesign CS6, I've created a presentation and shared it with 6 people via the DPS and Adobe Content Viewer. Now I have an edit to make and the results are not showing up when I preview on desktop or the iPad connected to the computer. I'm thinking I may have the wrong InDesign file open since I created different versions while troubleshooting some other problems (although I'm 99% sure I have the right one open). Is there a way I can use the Folio Builder to point me to the right InDesign file? Much like how the Links palette tells me where an image lives in my hard drive.
    Thanks!

    I found what I'm looking for. In the Folio Builder, go down to the Article view, click the drop down menu arrow, choose Relink. That will give the path of the InDD file. Or in my case, since I renamed the InDD file, this confused the Folio Builder into thinking the file no longer exists. So the Relink option also allows me to point the Article to the appropriate file.
    What's interesting is even though InDesign doesn't know where the file is at, it still retains the entire Folio.

  • 7.6 can only find files in the itunes folder - My Music files are all lost

    Since upgrading to itunes 7.6 all my old files that were located in My Music are no longer found by itunes. However all files in My Music/itunes are found.
    I have not changed the file names, what has happened?
    As I have loads of files in the old My Music folder it is a problem to redirect every file individually.
    I do have a backup of the computer but what do I restore as all the music files are where they have always been?

    Again many thanks. I have tried to tidy up the folders as per your idiot guide- which term is appropriate for me
    Under iTunes Media though I do not have  folders for Books,iPod Games, Mobile Applications, Movies, TV Shows so I only have  Auto Add to iTunes, Music, Downloads and Podcasts - My question here is is this OK.
    Next - Library files that you mention are there but do not end .itdb
    Next  - in the main iTunes folder followingon from Artwork and Media folders  there is some other  iTunes database stuff like Library Extras, Library Genius, Library and Music Library(xml) all dated 10/02/12 plus MimiPlayer .dll dated 21/02/14 and Set Up Short Cut dated22/03/14  
    AND there is also a Programme Files folder with a sub folder holding file folders called CD Configuration,iTunes Resources, iTunes Help Resources, iTunes Mini Player Resources and Mozilla Plugins all dated 24/03/14 ( when I downloaded the new iTunes) and then a lot of application extension stuff from 2011
    To recap I unistalled the old 32 bit iTunes and installed the new 11.1.5 (64 bit) version over the weekend  SO is any of the old stuff listed above required.
    Outcome right now is that as previously I can only call up the Downloaded music not Podcats or CD copies.
    Regards
    David Pugh

  • How to find out whether the String contains chinese characters

    I need to check if the string contains chinese characters in Java. Does anyone know how to do it? thx.

    Since Java strings contain UNICODE code points, check the content against the relevant page here - http://www.unicode.org/charts/ .

  • Can I copy files via the finder from my TM disk using Tiger?

    If I'm booted in Tiger and I have my TM disk mounted, can I just drag files over from the latest backup directory?

    If the data is enormous I would suggest doing things in small steps. Just take your time to pull things over gradually. Take a few hours as you wish and get it right. Good luck.

Maybe you are looking for

  • Why Can't I Remove iTunes Purchases from my Device?

    Now I know this didn't used to be an issue on my old iPhone 3GS, but am just not sure if it's to do with iTunes or the iOS. Basically, on my phone, I have two playlists that I sync - one is all my music videos, the other is songs that I want to liste

  • My PROs And CONs Opinion of This New Forum

    Hello, Since I've only been a member for a short time; my exposure has been limited; however, my opinions follow: PROs This forum has excellent support from "volunteer moderators" and Lenovo Staff. They are literally "all over the place" trying to as

  • Digital Signature for Inspection Plan and Routing

    Hi, Can someone please help me on the topic of how to activate Digital Signature for inspection plan changes. I need to activate Digital signature functionality for inspection plan or routing. Please guide me to any link or shared documents on this t

  • Indicator to include component scrap in the details screen of MFBF tcode

    Hi , There is an indicator in the 'Details' screen of MFBF transaction to "Include Component scrap". User has to select this indicator everytime he wants to include the component scrap or is there a way to save this setting ? If it is defaulted from

  • Chrush dump error and it become blue screen

    i am using sony vaio laptop vpceh25en it used to say that  chrush dump error and it become blue screen  and i dont know how to fix it. it was happen after a 8 months of time, now it happens.  it simultaniously shutdown with in 15 to 20 seconds after