Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Load html , js, css files from file system and outside the tomcat server

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to load html , js, css files from file system while running tomcat 7. Tried the following approach, and none of it works.
1) put <Context docBase="D:\temp\uploads\myfile" path="/MySharedHTML"/> under conf/server.xml

2) created folder conf\Catalina\localhost and put ROOT.xml under it with following content
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="D:\temp\uploads\myfile" path="/MySharedHTML"/>

when i tried to test my code with the following jsp file with tomcat running, nothing showed up

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Tag Example</title>
</head>
<body>da
<c:import url="/MySharedHTML/extraweb.html"/>
</body>
</html>
Please help!

Thank you
 
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it work when you type the URL into the browser rather than the import?
 
xi brian
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Does it work when you type the URL into the browser rather than the import?



as I mentioned the files are outside sever and located in the file system. It should not work that way
 
Bear Bibeault
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it should, that's the whole point of the docbase. By defining the context, you create the ability to serve files from that context. I assume you have a WEB-INF at that location?
 
xi brian
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Of course it should, that's the whole point of the docbase. By defining the context, you create the ability to serve files from that context. I assume you have a WEB-INF at that location?



No i do not, it is just simple file or images or js files
 
Bear Bibeault
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that's why it's not working. If you want to serve files from that context, it needs to be properly formed. At minimum it needs WEB-INF.
 
Saloon Keeper
Posts: 21422
143
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not put Context elements in server.xml. That practice has been discouraged since at least Tomcat version 4 and Tomcat 9 will be the point release shortly.

The recommended place to put Context elements is under TOMCAT_HOME/conf/Catalina/localhost (assuming standard configuration). However, note that if you do that, the "path=" attribute will be ignored by Tomcat and the actual path will be the name of the context XML file (minus its ".xml" extension).

I personally recommend using forward-slash syntax for all filenames referenced in Java (D:/temp/uploads/myfile). It makes stuff more OS-portable and spares you possible pain from the dreaded "backslash-is-escape" errors.

Since about Tomcat 7, a WEB-INF/web.xml file is no longer mandatory, but nonetheless, you cannot simply dump files and directories anywhere you like in any structure you like and have Tomcat serve them up. Tomcat is a web server, not a file server. Anything that you want Tomcat to serve to a web client (such as a browser) must be contained in a WAR and properly deployed to Tomcat.
 
a wee bit from the empire
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!