樣式加載不出來,瀏覽器控制臺報錯:Resource interpreted as Stylesheet but transferred with MIME type text/html
阿新 • • 發佈:2019-04-30
exce exp rri chain single nds tsp pat ext
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
import cn.com.jnpc.entity.User;
/**
* 登錄攔截
* @author Uself 2017-10-17 下午1:10:00
*
*/
public class LoginFilter extends StrutsPrepareAndExecuteFilter{
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,ServletException{
HttpServletRequest rqs = (HttpServletRequest)request;
HttpServletResponse rsp = (HttpServletResponse)response;
String requestUrl = rqs.getRequestURI();
String servletRequestUrl = rqs.getServletPath();
/*
* 非登錄請求時,判斷是否登錄過(是否有session)
* 有:繼續
* 沒有:重定向到登錄請求
*/
if((!requestUrl.contains(".action") && !requestUrl.contains(".jsp")) || "/singleAparment/loginAction.action".equals(requestUrl)){
super.doFilter(request, response, chain);
}
寫登錄的時候出現的問題,樣式時好時壞,瀏覽器控制臺看到的信息是:
Uncaught SyntaxError: Unexpected token <
Resource interpreted as Stylesheet but transferred with MIME type text/html。
但是css的加載路徑沒有錯,網上找了很多,看到http://bsr1983.iteye.com/blog/2246994,查看自己的登錄攔截過濾器結合debug,果然是攔截器寫的有問題,稍作改動下即可,不是action請求全部放過。
package cn.com.filter;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
import cn.com.jnpc.entity.User;
/**
* 登錄攔截
* @author Uself 2017-10-17 下午1:10:00
*
*/
public class LoginFilter extends StrutsPrepareAndExecuteFilter{
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,ServletException{
HttpServletRequest rqs = (HttpServletRequest)request;
String requestUrl = rqs.getRequestURI();
String servletRequestUrl = rqs.getServletPath();
/*
* 非登錄請求時,判斷是否登錄過(是否有session)
* 有:繼續
* 沒有:重定向到登錄請求
*/
if((!requestUrl.contains(".action") && !requestUrl.contains(".jsp")) || "/singleAparment/loginAction.action".equals(requestUrl)){
super.doFilter(request, response, chain);
}
else{
HttpSession session = rqs.getSession();
User user = (User) session.getAttribute("USER_INFO");
if(user == null || (user.getUserName() == null || user.getUserName().isEmpty())){
rsp.sendRedirect(rqs.getContextPath());
}
else{
super.doFilter(request, response, chain);
}
}
}
}
樣式加載不出來,瀏覽器控制臺報錯:Resource interpreted as Stylesheet but transferred with MIME type text/html