Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3761

Loading FreeMarker Templates from file system

    XMLWordPrintableJSON

    Details

    • Flags:
      Important

      Description

      Loading the freemarker template from the file system using templatePath in web.xml is not working as expected

      Example:

      My template path is --> "file://D://templates"

      try {
      if(templatePath!=null){
      if (templatePath.startsWith("class://"))

      { // substring(7) is intentional as we "reuse" the last slash templatePathLoader = new ClassTemplateLoader(getClass(), templatePath.substring(7)); }

      else if (templatePath.startsWith("file://"))

      { templatePathLoader = new FileTemplateLoader(new File(templatePath)); }

      }
      } catch (IOException e)

      { LOG.error("Invalid template path specified: " + e.getMessage(), e); }

      Line "templatePathLoader = new FileTemplateLoader(new File(templatePath));" always return null

      Fix:

      By changing the above line as below, it's working fine.

      templatePathLoader = new FileTemplateLoader(new File(templatePath.substring(7)));

        Attachments

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              greatvij Vijayakannan
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 24h
                24h
                Remaining:
                Remaining Estimate - 24h
                24h
                Logged:
                Time Spent - Not Specified
                Not Specified