jsp和tomcat的css mime类型的问题

时间:2018-08-25 01:33:03

标签: css jsp tomcat mime-types mime

我在tomcat上运行的jsp项目有问题。网站看起来像html的css文件,但不会加载它们。资源正确检索,因为通过检查,我看到css文件的200个正常代码。我在Tomcat 8.0上运行我的项目。代码如下:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- webapp/WEB-INF/web.xml -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Project</display-name>
  <mime-mapping>
    <extension>css</extension>
    <mime-type>text/css</mime-type>
  </mime-mapping>
  <welcome-file-list>
    <welcome-file>/</welcome-file>
  </welcome-file-list>
</web-app>

HomepageServlet

package webapp;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/", "/Homepage"})
public class HomepageServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        request.setAttribute("name", request.getParameter("name"));
        request.getRequestDispatcher("/views/Homepage.jsp").forward(request, response);       
    }
}

Homepage.jsp

<html>
  <head>
    <title>Project!!</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css">
  </head>
  <body>
    <div class="navbar-menu">
      <div class="navbar-menu-row">
        <div class="navbar-menu-first-row">
          <img src="images/logo.png" alt="">
        </div>
      </div>
    </div>
  </body>
</html>

项目的结构如下:

https://image.ibb.co/k9vj5K/Immagine.png

怎么了?

谢谢。

0 个答案:

没有答案