我遇到的一个filter问题
filter代码如下:
package util;
import
java.io.IOException;
import javax.servlet.http.*;
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.http.HttpServlet;
public class AdminFilter extends HttpServlet implements Filter
{
/**
*
*/
private static final long serialVersionUID = -5545950069282900798L;
protected FilterConfig filterConfig;
String LOGIN_PAGE= "Login.jsp ";
public void doFilter(final ServletRequest req, final ServletResponse res,final FilterChain chain)
throws
IOException,
ServletException {
// TODO 自动生成方法存根
HttpServletRequest hreq=(HttpServletRequest)req;
HttpServletResponse hres=(HttpServletResponse)res;
HttpSession session=hreq.getSession();
String flag= " ";
try
{
flag=(String)session.getAttribute( "isLogin ");
if( "true ".equals(flag))
{
chain.doFilter(hreq, hres);
}
else
{
hres.sendRedirect(LOGIN_PAGE);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void init(FilterConfig config) throws ServletException
{
// TODO 自动生成方法存根
this.filterConfig=config;
}
public void setFilterConfig(FilterConfig filterConfig)
{
this.filterConfig=filterConfig;
}
public void destroy()
{
this.filterConfig=null;
}
}
XML中配置如下:
<servlet>
<description> AdminFilter </description>
<display-name> AdminFilter </display-name>
<servlet-name> AdminFilter </servlet-name>
<servlet-class> util.AdminFilter </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> AdminFilter </servlet-name>
<url-pattern> /admin/* </url-pattern>
</servlet-mapping>
我现在通过http://localhost/Infosite/Login.jsp登入到http://localhost/Infosite/admin/admin_.jsp,总是出现一下错误:
HTTP Status 405 - HTTP method GET is not supported by this URL
我尝试了/admin/下的其他页面登入,都出现相同错误。于是我将配置改成如下:
<servlet-mapping>
<servlet-name> AdminFilter </servlet-name>
&