修改之后login.jsp可以打开了,但是进去的category管理页面显示500错误

修改之后login.jsp可以打开了,但是进去的category管理页面显示500错误

package com.imooc.web.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class AuthFilter implements Filter {
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}
	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		 HttpServletRequest req= (HttpServletRequest)request;
		 HttpServletResponse res=(HttpServletResponse)response;
		 String user=(String)req.getSession().getAttribute("existList");
		 String requestURI = req.getRequestURI();
		 String[] urls = {"/login.jsp", "/LoginServlet", ".js",".css", ".ico",".jpg",".png","/KaptchaServlet"};
		 boolean flag=true;
		 for(String url:urls) {
			 //找不到返回-1
			 if(requestURI.indexOf(url)!=-1) {
				 flag=false;
				 break;
			 }
		 }
		 if(flag) {
			 if(user!=null) {
		        	chain.doFilter(request, response);
		        	return;
		        }else {
		        	request.setAttribute("msg", "密码或用户名错误");
		        	res.sendRedirect(req.getContextPath()+"/login.jsp");
		        	return;
		        }
		 }else {
			 chain.doFilter(request, response);
		 }
        
		
		
	}
	
	public void destroy() {
		// TODO Auto-generated method stub
	}

	

	

}


报错如下:

EVERE: Servlet.service() for servlet [default] in context with path [/milestoneOne] threw exception

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.String

at com.imooc.web.filter.AuthFilter.doFilter(AuthFilter.java:23)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at com.imooc.web.filter.EncodeFilter.doFilter(EncodeFilter.java:30)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Thread.java:748)



正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好:

报错显示在第23行:

http://img1.sycdn.imooc.com//climg/5ea2bf9c090fa58b08320290.jpg

http://img1.sycdn.imooc.com//climg/5ea2bfb809bc2b6610590177.jpg

报错的意思是,ArrayList无法转换成String类型。

所以,这里同学要检查一下,登录成功后,同学像session中存放的existList的是不是集合呢?

要用对应的类型进行转换哦。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师