servlet 进行request 拦截,并判断该请求是否为“.action”请求。
servlet进行request拦截,并判断该请求是否为“.action”请求。如果是,则解析请求,获取请求的action;如果否,响应客户端为信息为:不可识别的的act...
servlet 进行request 拦截,并判断该请求是否为“.action”请求。
如果是,则解析请求,获取请求的action;如果否,响应客户
端为信息为:不可识别的的action 请求。
以上代码如何实现,本人小白,求大神啊 展开
如果是,则解析请求,获取请求的action;如果否,响应客户
端为信息为:不可识别的的action 请求。
以上代码如何实现,本人小白,求大神啊 展开
展开全部
package com.framework.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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 不允许访问.action
*
*/
public class LogFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
String url = httpServletRequest.getRequestURI();
if(url != null && url.endsWith(".action")) {
String redirect = httpServletRequest.getContextPath();
httpServletResponse.sendRedirect(redirect);
return;
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
web.xml
<filter>
<filter-name>LogFilter</filter-name>
<filter-class>com.framework.filter.LogFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LogFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询