写登录的时候出现的问题,样式时好时坏,浏览器控制台看到的信息是:
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;
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);
}
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);
}
}
}
}