0

I have an existing and working web app. This web app is a combination of HTML, CSS, Javascript, various Javascript libraries (Jquery etc.), images, and fonts.

Using Tomcat and a Java servlet, I want to be able to deploy this web app. I also need to be able to serve up different web pages based on the URL (that's where the servlets come in, I think).

I found this SO post which shows how to deploy a web app using Tomcat through Tomcat's webapps directory. This works perfectly, except that it only displays the one index.html file, and there is no way to change the displayed HTML based upon the user entered URL.

I also found this other SO post which describes how to return static HTML from a Java servlet. The problem with this, is that it only returns the HTML file, and none of the supporting files (Javascript, CSS, images etc.) which are also necessary for the web app to function properly.

Is it possible for the servlet to return all necessary files along with the HTML file, so that the web app functions properly?

Community
  • 1
  • 1
Zach Posten
  • 2,420
  • 2
  • 25
  • 36
  • if you just want to deliver static content, then tomcat might not be the the beset option. However, static file delivery should just work, if you put your files somewhere in the root folder of your webapp (NOT in WEB-INF). Also, your web.xml file could be configured in a way that it will serve static content (depending on your servlet mapping). So there's no simple answer to give you. could you possible past your web.xml file here? – Matthias Huttar Apr 25 '15 at 20:43
  • The solution to my problem was to move the web files within the `WebContent` folder but outside of the `WEB-INF` folder, and then to return the static html file; as you suggested. Could you post this as an answer to this question so that I can give you credit for the answer? Thank you for your help! – Zach Posten May 03 '15 at 20:10

2 Answers2

1

if you just want to deliver static content, then tomcat might not be the the beset option. However, static file delivery should just work, if you put your files somewhere in the root folder of your webapp (NOT in WEB-INF). Also, your web.xml file could be configured in a way that it will serve static content (depending on your servlet mapping). So there's no simple answer to give you. could you possible past your web.xml file here?

(as per request - made this an answer)

Matthias Huttar
  • 1,912
  • 12
  • 19
0

You do not have to specify the static content inside the servlet. Use your favorite HTML editor and design a webpage and include all the css/scripts in the html code. Then, send the user to that html with sendRedirect() or RequestDispatcher through the servlet.

Aswin
  • 511
  • 4
  • 11