Junqiang Zhang has the expectation of the paths to the files correct. /mywebapp/css/style.css is where that file should be located if exists in the spot indicated in the tree diagram.
I don't think the default servlet plays in to this... Can you post your web.xml ? I think perhaps one of your mappings is sitting on "/*" which would keep tomcat from serving static resources. On Mon, Mar 7, 2016 at 1:52 PM, Violeta Georgieva <violet...@apache.org> wrote: > Hi, > > 2016-03-07 19:37 GMT+02:00 Junqiang Zhang <junqiangzh...@gmail.com>: > > > > I have tested on Tomcat versions 8.0.30, 8.0.32, and 9.0.0.M3. > > > > A web app is put inside a folder (let's say the name of the foder is > > mywebapp) inside the Tomcat webapps directory. The folder for css > > files (let's say the name of folder is css) is located inside this web > > app folder. There is no index.html or index.jsp inside the web app > > folder. The structure is as the follows. > > > > Tomcat > > ----webapps > > -------mywebapp > > -------css > > -------styles.css > > -------images > > -------META-INF > > -------scripts > > -------WEB-INF > > -------classes > > -------someservlet.class > > -------lib > > -------src > > -------someservlet.java > > -------web.xml > > > > > > If the url-pattern of someservlet.class is set to / inside web.xml, > > Tomcat's "default" servlet [1] is mapped to "/". > The "default" servlet is a servlet that serves static resources as well as > serves the directory listings (if enabled). > > You should know that when you map your servlet to "/" then you will > override the "default" servlet mapping. > So you should ensure that your servlet will do the same as "default" one in > order to serve the static resources. > > When you map your servlet to "/someclass" then the static resources will be > served by "default" servlet as expected. > > Regards, > Violeta > [1] http://tomcat.apache.org/tomcat-8.0-doc/default-servlet.html > > > someservlet.class can be access using > > http://www.somewebsite.com/mywebapp > > > > The problem is that web browsers cannot locate styles.css at > > http://www.somewebsite.com/mywebapp/css/styles.css. Therefor, > > styles.css cannot be applied on the html file generated by > > someservlet.class. Probably other folders or files inside mywebapp > > directory cannot be accessed by web browsers too. > > > > If the url-pattern of someservlet.class is set to /someclass inside > > web.xml, someservlet.class can be access using > > http://www.somewebsite.com/mywebapp/someclass . Web browsers can > > correctly locate styles.css at > > http://www.somewebsite.com/mywebapp/css/styles.css > > > > Any solution to this problem? Does it solve this problem if I use > > Jetty or Glassfish? > > > > Thanks. > > Junqiang > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > > For additional commands, e-mail: users-h...@tomcat.apache.org > > >