File directory on a JSP

Hi,
I need to put a file directory on a jsp page. Does anyone know how to do that or have an example?
thanks,
Marc

Do you mean you want to display the contents of a directory, like Apache or Tomcat does? I'd read up on the File API first. Basically you'll want to use the list() or listFiles() method.

Similar Messages

  • Listing files on the webcontent directory that including .jsp files

    Hi ,
    I want to list all files on the directory that including .jsp files . How can I do this ?
    �f I use the following code in the jsp:
    java.io.File file = new java.io.File(".");
    String[] files= file.list();
    it returns me application server 's directory files. But I want to see webcontent directory files.

    You can use the method of ServletContext - getRealPath() to turn a website relative location into a real place on disk.
    In a generic way:
      <%
        String dir = application.getRealPath(request.getServletPath());
        File jspFile = new File(dir);
        File jspDir = jspFile.getParentFile();
        File[] files = jspDir.listFiles(); 
      %>Cheers,
    evnafets

  • Jsp-file="/WEB-INF/index.jsp" cannot load

              Hi,
              I am defining a servlet in the web.xml file using the following syntax.
              <servlet>
              <servlet-name>TestServlet</servlet-name>
              <jsp-file>/WEB-INF/index.jsp</jsp-file>
              </servlet>
              Then when I tried to access this servlet, I get a 404 not found error. The weblogic.log
              file complains with the following message:
              java.io.FileNotFoundException: no resource '/WEB-INF/index.jsp' in servlet context
              root '/home/dev/web/apps/MyApp'
              at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:293)
              at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:227)
              at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:200)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:115)
              at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:922)
              at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:886)
              at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:269)
              at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:380)
              at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:268)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              My jsp file in located in /home/dev/web/apps/MyApp/WEB-INF/index.jsp, I know weblogic
              doesn't support jsp under WEB-INF, however, according to Sun's Servlet specification,
              anything under web-inf should be accessible to getResource and getResourceAsStream
              method, and it looks like that's what weblogic implementation is using (from the
              error message). So I am not sure whether this is weblogic issue or I am doing
              something wrong. By the way, the above config in web.xml is supported in Tomcat.
              

              What version of WebLogic will incorporate Servlet spec 2.4 and allow jsp under
              web-inf?
              Chris
              "Narayan Anand" <[email protected]> wrote:
              >Regarding S-12864 - It will not work as stated in the solution in any
              >of
              >the available releases of WLS.
              >Please ignore that. I already informed the concerned person to correct
              >the
              >solution.
              >
              >The story behind this is:
              >Our engineering team is already aware of the fact that the request
              >dispatcher calls (include/forward) for a jsp under the web-inf directory
              >works in other app server - Tomcat.
              >Our engineering team had a discussion with the servlet/jsp spec experts
              >group for clarifying the spec and the tomcat implementation.
              >So the servlet expert group has decided to explicitly state in the spec
              >that
              >RD.forward() and RD.include() should be allowed access to resources in
              >/WEB-INF and it will be included in servlet spec 2.4. For now, WLS works
              >as
              >per the current specification.
              >
              >So far the story is - WLS will implement this in our next major release
              >which will be compliance with servlet spec 2.4.
              >In all the currently available WLS releases, accessed to a jsp under
              >the
              >WEB-INF directory is prohibited.
              >
              >--
              >Best Regards,
              >Narayan Anand
              >Developer Relations Engineer
              >BEA Systems, Inc.
              >
              >
              >
              >
              >
              >
              >"Ming Fan" <[email protected]> wrote in message
              >news:[email protected]...
              >>
              >> Thanks for the explanation. So this means weblogic treats such mapped
              >servlet request
              >> as a direct request to the jsp under WEB-INF, instead of forwarding
              >it to
              >some
              >> JspCompiler servlet and let that compiler servlet use some resource
              >loader
              >to
              >> load the jsp and then compile. I believe that latter implementation
              >approach also
              >> conforms the Servlet spec (it's a different way of treating the request,
              >I
              >guess).
              >>
              >> Now here's another question. According to Web logic Customer Support
              >Solution
              >> ID S-12864 (WLS 6.x - Cannot access JSP under the WEB-INF directory),
              >the
              >servlet
              >> should be able to get a request dispatcher, and then forward the request
              >to the
              >> jsp under WEB-INF. I am still using WLS 5.1, so does the above solution
              >apply
              >> to 5.1 also? It doesn't seem to work with 5.1. So is this a 5.1 problem
              >and I
              >> should upgrade to 6.1?
              >>
              >> Thanks.
              >>
              >> "Narayan Anand" <[email protected]> wrote:
              >> >Hi Ming,
              >> >
              >> >It is legal to put files under WEB-INF directory. But as mentioned
              >in
              >> >the
              >> >spec, it will be available only to servlet code and not directly to
              >client
              >> >request.
              >> >Read the last statement of the same paragraph in section9.5.
              >> >"Since requests are matched to resource mappings case-sensitively,
              >client
              >> >requests for '/WEB-INF/foo', '/WEb-iNf/foo', for example, should not
              >> >result
              >> >in contents of the web application located under /WEB-INF being returned,
              >> >nor any form of directory listing thereof.".
              >> >
              >> >So in your case, when you access the servlet which gets mapped to
              >> >/WEB-INF/your-jspfile, under no condition it should result in display
              >> >of jsp
              >> >contents.
              >> >It is working as per the specification.
              >> >
              >> >I hope this helps.
              >> >
              >> >Regards,
              >> >Narayan Anand
              >> >Developer Relations Engineer
              >> >BEA WebLogic Support
              >> >
              >> >
              >> >
              >> >"Ming Fan" <[email protected]> wrote in message
              >> >news:[email protected]...
              >> >>
              >> >> Actaully there are other ways to solve my problem. But what I am
              >> >interested to
              >> >> know is under the Servlet specification 2.3, is it legal to put
              >jsp
              >> >under
              >> >WEB-INF,
              >> >> define it in <jsp-file> xml tag, and should the JSP compiler be
              >able
              >> >to
              >> >see this
              >> >> as a resource. Apparently, Tomcat allows this behavior, so does
              >this
              >> >mean
              >> >Tomcat
              >> >> conforms better to the Servlet spec, or Tomcat is wrong but Weblogic
              >> >conforms
              >> >> better? Can anyone let me know what's the correct interpretation
              >of
              >> >section 9.5
              >> >> in servlet spec 2.3?
              >> >>
              >> >>
              >> >> "Jerrie Pineda" <[email protected]> wrote:
              >> >> >Try moving it to a different dir. You normally don't place jsp
              >file
              >> >> >in the
              >> >> >WEB-INF dir.
              >> >> >
              >> >> >
              >> >> >"Ming Fan" <[email protected]> wrote in message
              >> >> >news:[email protected]...
              >> >> >>
              >> >> >> Hi,
              >> >> >>
              >> >> >> I am defining a servlet in the web.xml file using the following
              >> >syntax.
              >> >> >> <servlet>
              >> >> >> <servlet-name>TestServlet</servlet-name>
              >> >> >> <jsp-file>/WEB-INF/index.jsp</jsp-file>
              >> >> >> </servlet>
              >> >> >>
              >> >> >> Then when I tried to access this servlet, I get a 404 not found
              >> >error.
              >> >> >The
              >> >> >weblogic.log
              >> >> >> file complains with the following message:
              >> >> >> java.io.FileNotFoundException: no resource '/WEB-INF/index.jsp'
              >> >in
              >> >> >servlet
              >> >> >context
              >> >> >> root '/home/dev/web/apps/MyApp'
              >> >> >> at
              >weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:293)
              >> >> >> at
              >> >weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:227)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:
              >2
              >> >0
              >> >> >0)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.ja
              >v
              >> >a
              >> >> >:115)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextI
              >m
              >> >p
              >> >> >l.java:922)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextI
              >m
              >> >p
              >> >> >l.java:886)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletConte
              >x
              >> >t
              >> >> >Manager.java:269)
              >> >> >> at
              >> >>
              >>
              >>>weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:380
              >)
              >> >> >> at
              >> >> >weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:268)
              >> >> >> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              >> >> >>
              >> >> >> My jsp file in located in
              >/home/dev/web/apps/MyApp/WEB-INF/index.jsp,
              >> >> >I
              >> >> >know weblogic
              >> >> >> doesn't support jsp under WEB-INF, however, according to Sun's
              >Servlet
              >> >> >specification,
              >> >> >> anything under web-inf should be accessible to getResource and
              >> >> >getResourceAsStream
              >> >> >> method, and it looks like that's what weblogic implementation
              >is
              >> >using
              >> >> >(from the
              >> >> >> error message). So I am not sure whether this is weblogic issue
              >> >or
              >> >> >I am
              >> >> >doing
              >> >> >> something wrong. By the way, the above config in web.xml is
              >supported
              >> >> >in
              >> >> >Tomcat.
              >> >> >
              >> >> >
              >> >>
              >> >
              >> >
              >>
              >
              >
              

  • How can we access the file/directory system in the server

    Hi friends,
    I have made a text editor attached with an audio player for my project.
    Both text editor and audio player are implemented in applet and put in to a
    jsp page using jsp:plugin. Text editor and player are separate applets running
    in the same page and from same server.A client who is using this editor may
    want to save the edited text files to the server as well as hear audio files from
    directories in the server.
    My question is how can we access the file/directory system in the server
    like we do in the local machine.When the user cliks save or openfromserver button
    in the editor, folder/files in the server must be displayed as we do with FileChooser.
    I am using Apache Tomcat 5,wiindows 2000 server, jdk1.5.
    manu

    You can't access it directly. But your applet can make net connections to the server, and the server can provide that kind of functionality. Generally this is easiest by making HTTP connections and having the server provide the functionality via the web server. (So in your case, JSPs or servlets on the server would list/deliver/create/modify/delete files, and the applets would invoke those JSPs and servlets.

  • Accessing file directory objects in 9.1 and /WEB-INF/classes zip

    It appears that in WebLogic 9.1 that the contents of the /WEB-INF/classes directory is being zipped up and placed in the /WEB-INF/lib directory under some arbitrary name.
    Is there a way to tell weblogic not to do this, but leave the /WEB-INF/classes directory expanded as it was in weblogic 8?
    Is there a particular reason, developers should be aware of, to why this is being done in 9.1 (9.x?)?
    Background :
    This particular app has a set of several hundred xml files that describe all of the screens (and thus the forms) of the app. They are used not only in the generation of the actual jsps (and believe it or not the action class as well as other supporting class, the app is really an interface to a legacy backend) but are also packaged within the WAR for the dynamic configuration of plugins used for complex validation; a quasi 'rules' engine.
    While there are several different versions of the app, and thus several different versions of xml files, there is only one version of the rules engine.
    The problem that has arised when running on 9.1 is the plugins access to those xml files.
    The plugin attempts to load the xml files by creating File object for the directory containing the xml files, and then iterating through the contents of that directory.
    The xml files are packaged within the /WEB-INF/classes directory and are thus accessible using a simple resource look-up (in actuality, a 'token' xml file is specified, looked-up as a resource and then used to determine the parent file directory's url).
    This has worked well enough as 'most' servers deploy the contents of /WEB-INF/classes directory in an expandable fashion. Obviously, this strategy readly breaks when those same contents are jar'd and placed in the /lib directory.
    It is prefered to not have to maintain a cataloge or index of the xml files because of the volume of xml files, the multiple versions of the xml files, and of course the volitility of the xml files, although this is an obvious option.
    I personally have mixed feelings about using a parent directory reference to load a set of resource files within a j2ee app. If anyone has any other suggestions, I would greatly appreciate it!
    Thanks
    Andrew

    Hi,
    Usually, the best approach would be to just to load the resources as InputStream and have a catalog (and I know this is what you do not want to do :-) So the only hacky workaround that I can think of would be to use something like Jakarta Commons Virtual File System (http://jakarta.apache.org/commons/vfs/) and read the .zip
    Regards,
    LG

  • Adding a fragment file (*.jspf) to a *.jsp file

    Adding a fragment file (*.jspf) to a *.jsp file
    What I did:
    1. Mkdir Web Pages\pages\common
    2. Create a *.jspf in directory
    3. Mkdir Web Pages\pages\common
    4. Create a *.jsp in directory
    5. Select page fragment
    Outcome:
    My *.jspf file is not shown in the combo list box of the "Select Page Fragment" dialig box, unless I create the *.jspf in the Web Pages directory.
    Question:
    Why?

    Since you're talking about "mkdir" etc. it sounds like you're trying to do this outside of the IDE. If so, you should note that a fragment is NOT just a .jspf file! All web forms in Creator have two files: a markup file (.jsp or .jspf) and a backing bean (.java). You must create both, by the same name, in the correct location, for the form to be considered a valid fragment. It's best to do this through the IDE.
    In case you did use the IDE and it's still not working, perhaps there's an issue with creating page fragments in subfolders. I know we had some bugs with creating regular forms in subfolders and most of those bugs were fixed but perhaps there are some additional issues for fragments.
    -- Tor

  • How do I find my CC Files Directory?

    Hello!
    Very new to the Creative Cloud.
    Trying to figure out the most basic thing--where can I find the Creative Cloud Files Directory? I want to be able to automatically backup my Photoshop and Indesign files, just in case my computer crashes.
    This site: Creative Cloud Help | Manage and Sync files --tells me if I save my files in this magical folder, they will automatically sync to the Cloud.
    Where is this folder? I'm using a Mac. I searched for it in Finder with no luck.
    Do I have to download another app?
    Help!
    Thanks,
    Super Newbie.

    doertel wrote:
    How do I put my cc files into bridge or camera raw?
    Please can you rephrase the question?

  • Error in setting permissions on file/directory $ORACLE_BASE/jre/1.1.8/LICEN

    Hi,
    On installing Oracle 9.2 on RedHat Linux release 4, I encounterd the
    following error:
    Error in setting permissions on file/directory
    $ORACLE_BASE/jre/1.1.8/LICENSE
    This error is encountered at the inital stage of installation after inputing all the
    required settings in the OUI. and at the Installing Java Runtinme Environment 1.1.8.1.0
    Could someone tell me why it happened and how to fix it? Your help is
    much appreciated.
    There was a post on this topic only in here and said to change the permissions of the
    ORACLE_BASE .......... I have tried out all these and all the permissions and the environment settings are correct but i'm not able to proceed with the installation even after a lot of trying.
    All you guys help is verry verry appreciated..........
    Thanks,

    Do the following and post the results:
    cd $ORACLE_BASE
    pwd
    ls -al
    cd jre
    pwd
    ls -al
    cd 1.18
    pwd
    ls -alI can't imagine anyone making recommendations without seeing what you've done.

  • Error in setting permissions of file/directory

    This is the error I am getting
    Error in setting permissions of file/directory /u01/app/oracle/jre/1.1.8/bin/i686/native_threads/.extract_args
    I am running RedHat 9 and obviously installing 9.2.0.
    Any ideas on why I might be getting this. I have set permissions for the oracle user for this directory.
    Thanks
    Dave

    from root try this command
    umask
    umask must set at 0022 ... if your server not set at this number use this command
    umask 0022

  • Error in setting permissions of file/directory /home/oracle/jre/1.1.8/LICENSE !

    Error in setting permissions of file/directory /home/oracle/jre/1.1.8/LICENSE ! Installation problem of 9i databse on redhat 7.3!!I installed sun jdk 1.3 or jdk 1.1.8_v3 and created a link for /usr/local/java !

    from root try this command
    umask
    umask must set at 0022 ... if your server not set at this number use this command
    umask 0022

  • How do i specify the filename for a binary file generated by a JSP?

    I am writing a report generator that has the ability to generate Excel files. The user clicks on a link (exporter.jsp), the page's content-type has been set to "application/vnd.ms-excel" which naturally prompts the user to either save to a file or open directly in Excel.
    It works fine, but requires the user to manually rename the generated file from "exporter.jsp" to "whatever.xls". Furthermore, Firefox will not let you rename the file in save dialog box, it just automatically saves the file as "exporter.jsp", you must rename it from the file browser.
    How do specify the output file name from within JSP?
    Btw, right clicking and selecting "save link as" allows for specifying the file name, but the file that is created is empty.
    Thanks

    You need to set the content-disposition header as well as the content-type.
    here is one article on the subject
    res.setContentType("application/vnd.ms-excel");
    res.setHeader("Content-Disposition", "attachment; filename=" + filename);

  • Get the file directory/location using JFileChooser

    Dear,
    How to get the file directory and it location with using JFilechooser after select the indicate file?
    Thanks

    There is an example at the top of JFileChooser's doc.
    http://java.sun.com/j2se/1.4.1/docs/api/javax/swing/JFileChooser.html

  • No remittance advice output in the 'Outbound Payment File Directory'

    We are working on an upgrade from 11i to R12.
    Configuration has created a profile for an electronic payment with a separate remittance advice. They have specified an outbound payment file directory. The EFT text file is generated in the proper directory (on the appserver); however, the remittance advice file went to the default directory on the dbase server. We want to pick up the file, rename and ftp to our printer from the 'outbound payment file directory'.
    Is this expected functionality or did we miss something in configuration?

    Manu,
    I do not think it is possible -- You may log a SR and confirm this with Oracle support.
    Where Can Be Found The Output File For The Transfer To The Bank [ID 730548.1]
    How To Change Nacha Payament Output Directory And Name [ID 786007.1]
    Thanks,
    Hussein

  • How to display XML file(as markup) in jsp page..?

    Hi All,
    * I have to display the XML file(as markup) in jsp page (Tree Format)....
    * My XML file is an java.io.file object , and how to view this XML file on my JSP page...........
    Thanks in Advance,
    JavaImran

    You mean you want to see the XML source?
    You need to replace the characters '<' and '&' with corresponding entities '&lt;' and '&amp;'. You can use replaceAll, but do the ampersands first.
    Then I suggest you probably want to put them in a <PRE> block.

  • Can I able to include image/.js file to payload-body.jsp

    Dear Experts,
    Could anyone please tell me that how can I refer a external javascript file from payload-body.jsp and where should I place the same. Also please tell the same to display an image. Please suggest me ASAP.
    Thanks,
    Rajesh

    Hi,
    so what source address of js file i have to give in jsp page.....in your case you can use below include command
    <jsp:include page="script/test.js" /> // here test.js is your .js file nameGenerally we need to place all jsp and js files under "jdevhome\jdev\myhtml\OA_HTML". In this case you can use
    <jsp:include page="test.js" /> // here test.js is your .js file nameor
    <%@include file="test.js" %>  // here test.js is your .js file nameregards,
    Anand

Maybe you are looking for