1

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

I have update my code by using controller to load html file and it works, but the related js, css and image does not load.

Please give some suggestions, and the code is shown below

@RequestMapping(value = { "/photo" }, method = RequestMethod.GET)
public void uploadPhoto(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String name = request.getParameter("name");
    // String filename =
    // URLDecoder.decode(request.getPathInfo().substring(1), "UTF-8");
    String filename = "tour.html";
    File file = new File("D:/temp/uploads/myfile", filename);
    response.setHeader("Content-Type", servletContext.getMimeType(filename));
    response.setHeader("Content-Length", String.valueOf(file.length()));
    response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
    Files.copy(file.toPath(), response.getOutputStream());
}

sever.xml in tomcat

    <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />
           <Context docBase="D:\temp\uploads\vtour" path="/MySharedHTML"/>

  </Host>
xibrian
  • 85
  • 2
  • 12

0 Answers0