我用了一个filter:SignonFilter检查用户权限问题,首先这个filter我已经在另外一个web测试中测试过没问题,可是我把这个filter加入到我的一个办公系统web应用中就出现了tomcat启动出错;
错误为:严重:Error FilterStart
严重:Context [/jspoa] startup failed due to previous errors
我的SignonFilter:为:
public class SignonFilter implements Filter
{
String LOGIN_PAGE="../index.jsp";
protected FilterConfig filterConfig;
//过滤处理的方法
public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
{
HttpServletRequest hreq = (HttpServletRequest)req;
HttpServletResponse hres = (HttpServletResponse)res;
HttpSession session = hreq.getSession();
String isLogin="";
try
{
isLogin=(String)session.getAttribute("isLogin");
System.out.println(isLogin);
if(isLogin!=null&&isLogin.equals("true"))
{
System.out.println("在SignonFilter中验证通过");
//验证成功,继续处理
chain.doFilter(req,res);
}
else
{
//验证不成功,让用户登录。
hres.sendRedirect(LOGIN_PAGE);
System.out.println("被SignonFilter拦截一个未认证的请求");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setFilterConfig(final FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}
//销毁过滤器
public void destroy()
{
this.filterConfig=null;
}
/**
*初始化过滤器,和一般的Servlet一样,它也可以获得初始参数。
*/
public void init(FilterConfig config) throws ServletException {
this.filterConfig = config;
}
}另外web.xml为:<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
JSP办公系统
</description>
<filter>
<filter-name>auth</filter-name>
<filter-class>com.jspdev.ch8.SignonFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>auth</filter-name>
<url-pattern>/office/*</url-pattern>
</filter-mapping>
<!--其他配置,例如:servlet配置等--></web-app>
错误为:严重:Error FilterStart
严重:Context [/jspoa] startup failed due to previous errors
我的SignonFilter:为:
public class SignonFilter implements Filter
{
String LOGIN_PAGE="../index.jsp";
protected FilterConfig filterConfig;
//过滤处理的方法
public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
{
HttpServletRequest hreq = (HttpServletRequest)req;
HttpServletResponse hres = (HttpServletResponse)res;
HttpSession session = hreq.getSession();
String isLogin="";
try
{
isLogin=(String)session.getAttribute("isLogin");
System.out.println(isLogin);
if(isLogin!=null&&isLogin.equals("true"))
{
System.out.println("在SignonFilter中验证通过");
//验证成功,继续处理
chain.doFilter(req,res);
}
else
{
//验证不成功,让用户登录。
hres.sendRedirect(LOGIN_PAGE);
System.out.println("被SignonFilter拦截一个未认证的请求");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void setFilterConfig(final FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}
//销毁过滤器
public void destroy()
{
this.filterConfig=null;
}
/**
*初始化过滤器,和一般的Servlet一样,它也可以获得初始参数。
*/
public void init(FilterConfig config) throws ServletException {
this.filterConfig = config;
}
}另外web.xml为:<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
JSP办公系统
</description>
<filter>
<filter-name>auth</filter-name>
<filter-class>com.jspdev.ch8.SignonFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>auth</filter-name>
<url-pattern>/office/*</url-pattern>
</filter-mapping>
<!--其他配置,例如:servlet配置等--></web-app>
解决方案 »
- 用myeclipse导入别人的工程不能运行(菜鸟问题)
- jsp上传文件.带中文参数.文件名也是中文 .
- jdbc返回前台页面的代码该如何写
- JSF 和 Struts 那个更好?
- 台湾那一个很好的技术,谁知道怎么做。
- J2SDK+Apache+Tomcat配置的问题?
- 在<textarea></textarea>文本区域中排好格式(不如:回车换行、空格)添加到数据库后,如何在JSP中按照原来的格式显示在页面上。
- 急问:关于连接数据库bean的几个问题?~~~~~~~~~waiting............
- tomcat4.1.18配置问题?
- DB2 Personal Edition能用JSP吗??
- 请教个问题,使用struts抛出如下异常 (真急,谢谢大家来帮忙)
- 那为老大告诉我函数的名字啊?
or when excute?
public class SignonFilter implements Filter?这个地方定义成:
public class SignonFilter extends HttpServlet implements Filter
2.
public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
这个地方定义成final形式?去掉看看
public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain)throws IOException,ServletException