• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 67451
173
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: 67451
173
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: 67451
173
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: 22503
151
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.
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic