Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 749799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:28:36+00:00 2026-05-14T14:28:36+00:00

I have a few HTML files that I’d like to include via tags in

  • 0

I have a few HTML files that I’d like to include via tags in my webapp.

Within some of the files, I have pseudo-dynamic code – specially formatted bits of text that, at runtime, I’d like to be resolved to their respective bits of data in a MySQL table.

For instance, the HTML file might include a line that says:

Welcome, [username].

I want this resolved to (via a logged-in user’s data):

Welcome, user@domain.com.

This would be simple to do in a JSP file, but requirements dictate that the files will be created by people who know basic HTML, but not JSP. Simple text-tags like this should be easy enough for me to explain to them, however.

I have the code set up to do resolutions like that for strings, but can anyone think of a way to do it across files? I don’t actually need to modify the file on disk – just load the content, modify it, and output it w/in the containing JSP file.

I’ve been playing around with trying to load the files into strings via the apache readFileToString, but I can’t figure out how to load files from a specific folder within the webapp’s content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:28:36+00:00Added an answer on May 14, 2026 at 2:28 pm

    but I can’t figure out how to load files from a specific folder within the webapp’s content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.

    If those files are located in the webcontent, use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path. This works if the WAR is exploded in the appserver (most does it by default, only Weblogic doesn’t do that by default, but this is configureable IIRC). Inside servlets you can obtain the ServletContext by the inherited getServletContext() method.

    String relativeWebappURL = "/html/file.html";
    String absoluteFilePath = getServletContext().getRealPath(relativeWebappURL);
    File file = new File(absoluteFilePath);
    // ...
    

    Alternatively, you can put it in the classpath of the webapplication and make use of ClassLoader#getResource():

    String relativeClasspathURL = "/html/file.html";
    URL absoluteClasspathURL = Thread.currentThread().getContextClassLoader().getResource(relativeClasspathURL);
    File file = new File(absoluteClasspathURL.toURI());
    // ...
    

    As to the complete picture, I question if you have ever considered an existing templating framework like Freemarker or Velocity to ease all the job?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML files that I need to distribute in MS Word doc
I have a few lines of PowerShell code that I would like to use
I have few different applications among which I'd like to share a C# enum.
I have a few Visual Studio Solutions/Projects that are being worked on in my
We have a few projects that involve building an application that is composed of
I have a few hand-crafted web pages. When deploying them I would like to
I have few asynchronous tasks running and I need to wait until at least
I'm a newbie to pgsql. I have few questionss on it: 1) I know
How do I create subdomains in ASP.NET? I have few links on my homepage(Home.aspx)
We have a few very large Excel workbooks (dozens of tabs, over a MB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.