How to read resource file under the WEB-INF through ClassPathResource

I have an xml file under the directory WEB-INF but WEB-INF/classes, I want to read it through ClassPathResource class from Spring, and where I read this xml file is not in a Servlet class, how can I do? Thank you.

Webmethods should be able to handle it. if not you should convert the tline content into one xstring and pass it to webmethods.
othe option
if you are on WAS6.20 and above you can use BSP to achieve what you are looking for.
Regards
Raja

Similar Messages

  • How to access the file in the WEB-INF Folder

    hi..
    i want to access a xml file, using servlet, which is placed under WEB-INF folder.
    Please tell me how can i access the file.
    I am using WSAD to develop the application
    Thanx in advance.

    I haven't tried accessing an XML file that is placed in WEB-INF folder.
    Files under WEB-INF are usually protected from client/browser access, but a Servlet may be able to access it (not sure though).
    What problems are you facing when you try to access an XML file in the WEB-INF folder?
    If you can't access it from the WEB-INF folder , place it in any folder except the WEB-INF folder.
    Also, if you want to protect the XML file then you could password protect it or deny access to it via .htaccess file, or simply return a 403 forbidden header.

  • How to load/save a file in the WEB-INF?

    how can i load and save files in the WEB-INF directory using servlet?

    This doesn't save files. And in order to reuseability and maintainability, I'd rather use java.io and passing the path/filename around in File object.
    You can retrieve the absolute path for "/WEB-INF" byString absoluteWebInfPath = getServletContext().getRealPath("/WEB-INF");Then you can use that to read/write files.
    File file = new File(absoluteWebInfPath, "filename.ext");
    InputStream input = FileUtil.read(file);
    FileUtil.write(file, input);and so on.

  • Storing .jsp files in the web-inf directory

    Has anyone ever heard about storing JSP files in the web-inf directory instead of the web app root directory.
    Apparently it improves security.
    If this is so, how is the user suppose to access the jsp file since I thought that users were not able to access what is stored in the web-inf directory.
    Any thoughts
    Thanks
    Nat

    I didn't tyr this but I think it is possible. You can do it using <servlet-mapping/> as you do with any other servlet.
    For example include lines below, in web.xml of web-inf,
    <servlet>
    <servlet-name>ReportRouter</servlet-name>
    <jsp-file>/web-inf/jsp/ReportRouter.jsp</jsp-file>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>ReportRouter</servlet-name>
    <url-pattern>/myrouter</url-pattern>
    </servlet-mapping>
    This may work. Don't you think so?
    Sudha

  • Reading HTML files on the web

    How can I read an HTML on the web and extract data from the HTML file into my VI. I am using SHDocVw.IWebBrowser2 activeX control to access the web page but I cannot figure out how to read the HTML into my VI. Is there an easy way to do this?
    Jim

    Hi Jose Perez,
    First off, are you repeatedly searching the string for certain patterns, or just searching the string for the specified pattern once? If possible, your best bet may be to only search part of the string if you know that it will be in a consistent format, thereby eliminating large sections of the string. If you are searching in a cascading order (searching for one pattern that is always before the next ones), then you could split the string at the first pattern and only search the latter portion.
    Also, you might want to consider making a new post since this thread is four years old.
    Bill E. | Applications Engineer | National Instruments

  • How to include resource files in the server classpath

    Hello,
    I deployed an EAR on weblogic. I have couple of resource files that I need to put in the server classpath. I get the following error when I try to access the web app.
    java.util.MissingResourceException: Can't find bundle for base name HtmlTemplates, locale en_US
    If I copy the resource files in WEB-INF/classes then the error goes away and the application works well. Can someone please tell me a better way to include the resource files in the WebLogic ?
    Thanks,
    Anu

    Hi Anu,
    Putting the resource files in WEB-INF/classes is the correct and good way!
    Simon

  • How to read, write file inside the JAR file?

    Hi all,
    I want to read the file inside the jar file, use following method:
    File file = new File("filename");
    It works if not in JAR file, but it doesn't work if it's in a JAR file.
    I found someone had the same problem, but no reply.
    http://forum.java.sun.com/thread.jsp?forum=22&thread=180618
    Can you help me ? I have tried this for all night !
    Thanks in advance
    Leo

    If you want to read a file from the JAR file that the
    application is packaged in (rather than a separate
    external JAR file) you do it like this ...
    InputStream is =
    ClassLoader.getSystemResourceAsStream("filename");Better to use
    this.getClass().getClassLoader().getResourceAsStream();
    From a class near to where the data is. This deals with multiple classloaders properly.

  • Can't read pdf-files from the web

    Some pdf-files from the web (using Safari 6) is not readable on my iMac, OSX 10.7.4.
    I get a lot of
    instaed of text.
    Why?
    /Karin

    It happens even to me (iMac late 2006, OS X 10.6.8, Safari 5.1.7(6534.57.2)), but instead of ??? I get black screens. Here some links to several PDF files:
    http://www.heathrowairport.com/static/Heathrow/Languages/Downloads/italian-secur ity-guide.pdf
    http://www.crs.lombardia.it/ds/ccurl/487/15/2008_10_15_Manuale_di_installazione_ e_configurazione_del_CRS_Kit_per_Mac_V1.0.pdf
    http://tda.panasonic-europe-service.com/docs/2z508fef28z3z36c0fz6974z706466z23zc 6217222fafecd42377558ba5cd29331bfd3c26a/tsn2/data/EU/TXP42ST50E/OI/890961/TQB0E2 271C.pdf
    http://www.trenitalia.com/cms-file/allegati/trenitalia/treni/Frecciargento_sched atecnica.pdf
    Luciano

  • How to read some files inside the jar

    Hi,
    I have an applet that runs with JWS. The user can input some information and then I need to show this information in a web page. As the application can be run offline, I cannnot use JSP�s to generate the web page. The information is saved in a xml file, so I use a xsl parser to generate the html code. The problem is that I have to include some javascript files (.js). I put these files inside the jar, but, how can I read these files, or how can I reference these files from inside the html page ?
    Thanks !

    You can use getClass().getResource(classpath)
    to get a stream version of the data from your
    jar file. If you need to put it in a file, you
    can write that stream to a file in a temp directory.
    classpath is the classpath of your js file

  • How to read a file inside the JAR file

    Hi All,
    I want to save some preferences in a file called "preferences". I kept the preferences file under my java package.
    If i am running the code inside the NetBeans 6.9 IDE it's working file. But once i have created a JAR and try to run the application, it couldn't find the path.
    Please help me that how to resolve this issue. I don't want to save this preferences file outside of my JAR (i.e) within my java package.
    Here is the code,
    package mypackage;
    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    public class ReadFile
        private void writeFile()
            try
                OutputStream out = new FileOutputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                PrintWriter writer = new PrintWriter(out);
                writer.println("Hello Java!");
                writer.close();
                out.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        private void readFile()
            try
                FileInputStream fi = new FileInputStream(getClass().getClassLoader().getResource("mypackage/preferences").getPath().replace("%20", " "));
                BufferedReader br = new BufferedReader(new InputStreamReader(fi));
                System.out.println(br.readLine().trim());
                br.close();
                fi.close();
            catch (Exception ex)
                System.out.println(ex.getMessage());
        public static void main(String[] args)
            ReadFile read = new ReadFile();
            read.writeFile();
            read.readFile();
    }If i run the JAR, i get the following error message,
    {color:#ff0000}*file:\my jar path\jarname.jar!\mypackage\preferences (The filename, directoryname, or volume label syntax is incorrect)*{color}

    Thanks sabre150,
    sabre150 wrote:
    You cannot update a running jar file. I am sorry. I didn't know about it. Thanks to point out.
    There are two ways I approach this depending on my exact requirements -
    1) use the java.util.prefs.Preferences APII will try this one
    >
    2) if not already present I copy the preferences file from the jar to a known place. I use a directory in the user's home directory and normally make the directory name the program with a '.' prefix.
    One cannot access files in a jar file using the File API. One needs to use the getResource() or getResourceAsStream() methods on Class or ClassLoader.

  • How to read multiple files in the same folder?

    Suppose I have 100 txt files in the same folder, and I want to read them one by one. (order is not important). File name is also part of the information I want.
    How to do that?
    Thanks

    You need to use the directory to create a File (use the path name, w/o a file name). Then you need to ask for a list() (array of String containing name). To do that you'll need to implement the FilenameFilter interface, writing an accept() method that returns true if the file's name ends with ".txt".
    If that's not perfectly clear, try the java.io API docs and return more specific questions.

  • How to include resource files in the application and how to retrieve ?

    Hi,
    I want to include resource file in my application jar file and retrieve data from the file ......Is there any way for it? How i create these resources files and how i include them?.........Which classes shall i use for retrieving the data from these files?.........Any kind of help would be appreciated........Iam using NetBeans IDE 6.1,CLDC1.0 and MIDP 2.0........Thanx,in advance..........

    How i create these resources files and how i include them?How you create the files will depend on what resources you need to include.
    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    db

  • How to read from file just the 2nd line onwards?

    hi guys can anyone help me?
    how to read from the file if the file was like this
    2 2
    2 1
    1 3
    and i want to get the 2 1 ,just the 2nd line and the 3rd line?
    i tried using the string tokenizer but it kept saying
    no such element
    i tried this code:
    StringTokenizer cols = new StringTokenizer(s," ");
         temp =  (String) (cols.nextElement());
         num_rows = Integer.parseInt(temp);
         temp = (String) (cols.nextElement());
         num_cols = Integer.parseInt(temp);
         matrix = new int [num_rows][num_cols];
         // to add all the values in the data file into an array                         
         while ( s!= null ) {
         StringTokenizer st1 = new StringTokenizer (s);
               while (st1.hasMoreTokens()){
                     for (i=0; i<num_rows; i++){
                          for (j=0; j<num_cols; j++)
                             matrix[i][j] = Integer.parseInt
                                ( st1.nextToken());
                } // whilecan anyone please help me?
    thanks

    This will read the file witout the first line:
    import java.io.*;
    import java.util.*;
    public class Read2
    public static void main (String[] args)
         try
              FileReader     file = new FileReader("f.txt");
              BufferedReader buff = new BufferedReader(file);
              String         line  = buff.readLine();
              while (line != null)
                   line = buff.readLine();
                   System.out.println(line);
              buff.close();
         catch(IOException e)
              System.out.println("IO Error");
    }       Noah

  • How to download a file from the web

    Say, a PDF.

    Hi!
    Your question is marked as a Firefox OS question which is Mozilla's own mobile operating system. Thanks for contacting Mozilla Support!
    It seems that PDFs cannot be downloaded from the web at this moment, however there are apps from the marketplace you can download to open already downloaded PDFs available on your microSD card.

  • How  to read all files  under a folder directory in FTP site

    Hi Experts,
    I use this SQL to read data from a file in FTP site. utl_file.fopen('ORALOAD', file_name,'r');
    But this need to fixed file name in a directory. However, client generate output file with auto finename.
    SO do we have any way to read all file by utl_file.fopen('ORALOAD', file_name,'r');
    We need to read all file info. because client claim for security issue and does not to overwirte output file name,
    we must find a way to read all file in output directory.
    Thanks for help!!!
    Jim

    If you use Chris Poole's XUTL_FTL package, I believe that contains functions that allows you to query the directory contents.
    http://www.chrispoole.co.uk/apps/xutlftp.htm
    Edited by: BluShadow on Jan 13, 2009 1:54 PM
    misread the original post

Maybe you are looking for