Variable Changes when Publishing to Web Server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SDyke
    New Member
    • Aug 2006
    • 17

    Variable Changes when Publishing to Web Server

    In a class I have a string variable with a value of:

    filePath = "file://" + "gvas400/home/sde/pdffiles/817739P1.pdf";

    This works great when I run the web app on my local web host server.

    However, when I publish to our as400 Web server the following error appears when I try to view the file. I takes out one of the "/" just before the gvas400 server name.

    Error Message: No such path or directory. file:/gvas400/home/sde/pdffiles/817739P1.pdf

    Can someone help?
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by SDyke
    In a class I have a string variable with a value of:

    filePath = "file://" + "gvas400/home/sde/pdffiles/817739P1.pdf";

    This works great when I run the web app on my local web host server.

    However, when I publish to our as400 Web server the following error appears when I try to view the file. I takes out one of the "/" just before the gvas400 server name.

    Error Message: No such path or directory. file:/gvas400/home/sde/pdffiles/817739P1.pdf

    Can someone help?
    Try using the root contex.

    Comment

    • SDyke
      New Member
      • Aug 2006
      • 17

      #3
      Originally posted by r035198x
      Try using the root contex.
      Can you give me an example of the syntax?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by SDyke
        Can you give me an example of the syntax?
        This would depend on the platform you are using so you might want to read about it first. Here is how I do it.

        I have a method, getContextName in my Utils class
        Code:
        String rootContext = Utils.getContextName(config);
        To call my servlets I do something like
        [/size]
        Code:
         
         
        String path= "/" + rootContext + "/homePage.jsp?include=/ChangePolicyClients";

        Comment

        • SDyke
          New Member
          • Aug 2006
          • 17

          #5
          Originally posted by r035198x
          This would depend on the platform you are using so you might want to read about it first. Here is how I do it.

          I have a method, getContextName in my Utils class
          Code:
          String rootContext = Utils.getContextName(config);
          To call my servlets I do something like
          [/size]
          Code:
           
           
          String path= "/" + rootContext + "/homePage.jsp?include=/ChangePolicyClients";
          First thank you for time in helping me with this issue. I wish I was more learned in Java programming.

          I have tried everything and sill this code:

          protected void doPost(HttpServ letRequest arg0, HttpServletResp onse arg1) throws ServletExceptio n, IOException {
          String dwgString = DrawingInquiryS ervlet.getFileP ath;

          ServletOutputSt ream out = arg1.getOutputS tream();
          arg1.setContent Type( "applicatio n/pdf" );


          String filePath = "http://gvas400/home/sde/pdffiles/817739P1.pdf";

          InputStream in = null;
          try {
          in = new BufferedInputSt ream
          (new FileInputStream (filePath));
          int ch;
          while ((ch = in.read()) !=-1) {
          out.print((char )ch);
          }
          }
          finally {
          if (in != null) in.close(); // very important
          }

          gives me this error:

          Error Message: http:\gvas400\h ome\sde\pdffile s\817739P1.pdf (The filename, directory name, or volume label syntax is incorrect)

          What is stripping out the "/" from my path?

          Comment

          • pronerd
            Recognized Expert Contributor
            • Nov 2006
            • 392

            #6
            Code:
            String filePath = "http://gvas400/home/sde/pdffiles/817739P1.pdf";
            This would seem to be the problem. This is a URL not a system path. If you want to read from a URL you can not use the File object. To use the file object you need to use the file path of where the file resides. If you want to use a URL you need to use the URL object.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by SDyke
              First thank you for time in helping me with this issue. I wish I was more learned in Java programming.

              I have tried everything and sill this code:

              protected void doPost(HttpServ letRequest arg0, HttpServletResp onse arg1) throws ServletExceptio n, IOException {
              String dwgString = DrawingInquiryS ervlet.getFileP ath;

              ServletOutputSt ream out = arg1.getOutputS tream();
              arg1.setContent Type( "applicatio n/pdf" );


              String filePath = "http://gvas400/home/sde/pdffiles/817739P1.pdf";

              InputStream in = null;
              try {
              in = new BufferedInputSt ream
              (new FileInputStream (filePath));
              int ch;
              while ((ch = in.read()) !=-1) {
              out.print((char )ch);
              }
              }
              finally {
              if (in != null) in.close(); // very important
              }

              gives me this error:

              Error Message: http:\gvas400\h ome\sde\pdffile s\817739P1.pdf (The filename, directory name, or volume label syntax is incorrect)

              What is stripping out the "/" from my path?
              Wait a minute. Are you trying to read a .pdf using a FileInputStream ?

              Comment

              Working...