Problems retrieving a file uploaded through a web service

I have a web service that uploads a few files to the server.   The service uses Glassfish V3.  The folder and files it creates can be found in my domain folder in the Netbeans config/GF3 folder.  When I try to read that file afterwards from my web application (which contains the web service), or from any other web application using the same server and domain, I get a "resource not available" message.  What am I doing wrong?

For example, my web service operates from this url :

and is told to write to errors/

Say my file is test.txt, none of these paths gets me to the file that was written:

I am using Netbeans 6.9.1 and J2EE to develop this application.
Who is Participating?
Sathish David Kumar NArchitectCommented:
you want mention apsolutae path not relative path ??

can you post the code
EmilieAuthor Commented:
The code below shows the steps I take to save the file from the web service.  I also save a copy of the path to each file to my database.

The second part is in a different application (running with the same server, and associated to the same domain).  I only included the method that tries to retrieve the path.

The method getPath() returns the path stored in my database.  In this case for instance, it will return :

If I put that directly in my browser, the file will open correctly.  But the image won't show in my page.  Any anchor tag pointing to it will also not prompt any action from the browser.

I have also tried storing the relative path, in which case I get something like:

This also doesn't work.

Right now I'm testing on a pc, with a local server.  I don't know if I would encounter the same problem once it's deployed to an actual server. (I don't have access to a staging environment yet).
public class ErmResource {
public static final String ERROR_RESPOSITORY = "errorReports\\";

public String loadFile(@Context HttpServletRequest request) {
     try {
       RESTwsEJBRemote wsEJB = (RESTwsEJBRemote) new InitialContext().lookup("ejb/wsEJB");
       zipFile = new File(fileRepository + fileName);

try {
   if (zipFile.getPath().lastIndexOf("\\") != -1 && !zipFile.exists()) {
        new File(zipFile.getPath().substring(0, zipFile.getPath().lastIndexOf("\\"))).mkdirs();
            return true;
} catch (Exception e) {
     return false;



public class RetrieveDetailedError extends AJAXAction {

public String createAttachments(int appId, String errorUID) throws Exception {
        String html = "";
        try {
            int errorId = searchEJB.getErrorId(errorUID);
            List<Attachment> attchmnts = searchEJB.getAttachments(errorId, " not in ('image')");
            String screenshot = "";
            String logs = "";
            String others = "";

            html += "<div class='trigger'>";
            html += "<div class='sectionTitle' id='mouseover'><img class='expand' src='../images/collapsed.png' align='left'/>";
            html += "<p>Attachments</p></div></div>";
            html += "<div class='toggle_container'>";
            html += "<div class='block'><p>";

            if (!attchmnts.isEmpty()) {
                Iterator itr = attchmnts.iterator();
                while (itr.hasNext()) {
                    Attachment attchmnt = (Attachment);
                    int i = 1;
                    String name = findAttachmentName(attchmnt.getpath());
                    if (name.length() < 2) {
                        name = attchmnt.getpath();

                    if ("log".equalsIgnoreCase(attchmnt.getType())) {
                        logs += "<a class='default' href='" + attchmnt.getpath() + "'>" + name + "</a><br/>";
                    } else if ("image".equalsIgnoreCase(attchmnt.getType())) {
                        screenshot += "<a class='default' href='" + attchmnt.getpath() + "'>Image" + i + "</a><br/>";
                    } else {
                        others += "<a class='default' href='" + attchmnt.getpath() + "'>" + name + "</a><br/>";


                if (screenshot.length() > 1) {
                    html += "<p><b>Screenshot</b><br/><br/>" + screenshot + "</p>";

                if (logs.length() > 1) {
                    html += "<p><b>Logs</b><br/><br/>" + logs + "</p>";

                if (others.length() > 1) {
                    html += "<p><b>Other Attachments</b><br/><br/>" + others + "</p>";

                html += "</p></div>";
                html += "<img class='bottom' src='../images/tabBoxBottom.png'/></div>";
                html += "<img class='bottomShadow' src='../images/tabShadowBottom.png' />";

        } catch (Exception e) {
            throw e;
        return html;


Open in new window

EmilieAuthor Commented:
Thanks, these links were pretty useful.  Ended up solving my problem by saving the file using the Servlet Context but recording its location in the database using the URI context.  I was thus able to retrieve the files from another web app.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.