The problem of accessing css File under WEB-INF in eclipse

the issue that the development tool I use is eclipse, may have nothing to do with open tools, but it"s worth mentioning. As shown in figure 1, an index.jsp file is created under WebContent, and an index.jsp file is also created in WebContent"s WEB-INF.
use < jsp:forward > in index.jsp under webcontent with the following code

<body>
    <jsp:forward page = "/WEB-INF/jsp/index.jsp" ></jsp:forward>
</body>

how can index.jsp in WEB-INF access peer css files?

Thank you for your advice

1 figure 1

Mar.06,2021

Files created in

WEB-INF cannot be accessed from outside directly , which is specified in the servlet api standard, and all web containers are implemented in this way. If you want to use
, you can access it indirectly through code (such as spring mvc) or using the include tag in an accessible jsp).

access to protected areas for static resources

package com.example;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.apache.catalina.servlets.DefaultServlet;

public class StaticServlet extends DefaultServlet
{
   protected String pathPrefix = "/static";

   public void init(ServletConfig config) throws ServletException
   {
      super.init(config);

      if (config.getInitParameter("pathPrefix") != null)
      {
         pathPrefix = config.getInitParameter("pathPrefix");
      }
   }

   protected String getRelativePath(HttpServletRequest req)
   {
      return pathPrefix + super.getRelativePath(req);
   }
}


web.xml configuration is being applied

   
    
<servlet>
    <servlet-name>StaticServlet</servlet-name>
    <servlet-class>com.example.StaticServlet</servlet-class>
    <init-param>
        <param-name>pathPrefix</param-name>
        <!-- -->
        <param-value>/WEB-INF/static</param-value>
    </init-param>       
</servlet>

<servlet-mapping>
    <servlet-name>StaticServlet</servlet-name>
    <url-pattern>/static/*</url-pattern>
</servlet-mapping>  




The main reason why the

problem has been solved
is that in project development, the jsp page should be placed under WEB-INF , and when the jsp is accessed directly through the browser, it is that is not accessible by . If you put the jsp page under webcontent , and just visit directly, you don't have to say much; if you put the jsp page under WEB-INF , with several different methods, the method I use is to create an index.jsp, under webcontent to directly access the files under webcontent so as to jump to the jsp in WEB-INF . The code is as follows

<jsp:forward page = "/WEB-INF/jsp/index.jsp" ></jsp:forward>

but css,js,images and other files cannot be placed under WEB-INF , so you can't find it, just put it under webcotent , and import css outside the relative path. The code is as follows

<link rel="stylesheet" href="css/index.css" type="text/css"></link>

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32755-40e59.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32755-40e59.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?