1. 程式人生 > >Resource interpreted as Stylesheet but transferred with MIME type text/html:解釋

Resource interpreted as Stylesheet but transferred with MIME type text/html:解釋

這種錯誤,基本上各個階段,由各個階段的出錯型別,目前,我接受的比較淺,引起方式是,用註解配置servlet對映的時候引起的,我的是因為css樣式沒有引入引起的,
在這裡插入圖片描述
經過大神的指點,原因是找出了,單個人能力有限,理解有限。看原因

@WebServlet("/")   //看這裡
public class UpdateUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException { doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); } }

由於我在瀏覽器上輸入了http://localhost:8080/day12/list
在tomcatd內部執行機制的引導下,查詢對映為list 的 Servlet 由這個servlet進行處理,看這個servlet:

@WebServlet("/list")
public class UserListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); UserService us = new UserService(); List<User> list = us.findAllContact(); HttpSession session = request.getSession(); session.setAttribute("list",list); request.getRequestDispatcher("/list.jsp").forward(request,response); } }

這個servlet 請求轉發到list.jsp介面中去了,這是一次請求,tomcat內部機制找到了list.jsp,切記,如果list.jsp 是一個html檔案的話,那麼,請求的頁面將會是一個空白,原因是,最上面的那個servlet的對映方式給阻擋住了,也就是執行的是最上面的那個servlet,所以瀏覽器控制檯就會報那個響應型別的錯誤,
繼續走,,,,,
因為jsp ,把本身就是一個servlet,所以,tomcat內部機制,就會比配到這個list.jsp,但是,list.jsp裡面有好些東西,例如,引入的外部樣式,外部js指令碼,
這些東西也是一個請求看圖:
在這裡插入圖片描述
點進去,再看
在這裡插入圖片描述
畫橫線的東西,在tomcat的內部匹配機制中沒有找到對應的servlet,只能把它交給萬能的匹配 “/” ,這個表示,它可以匹配所有,如果你不信,可以在web.xml中設定一個這樣的對映,就知道效果了,而,這個servlet有一句這樣的程式碼
response.setContentType(“text/html;charset=utf-8”);
表示響應的資料型別,所以,就出現了
Resource interpreted as Stylesheet but transferred with MIME type text/html:
解決方式是,改一改那個對映。。。。。
寫的不太好,但至少是這個錯誤,就能解決。。。。。