给一个例子你,希望对你能有帮助
package dao;
import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import po.login;
public class permissionFilter implements Filter {
private FilterConfig filterConfig;
private FilterChain chain;
private HttpServletRequest request;
private HttpServletResponse response;
public void destroy() {
this.filterConfig = null;
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain chain) {
this.chain = chain;
this.request = (HttpServletRequest) servletRequest;
this.response = ((HttpServletResponse) servletResponse);
// 获取当前页面文件名此处url为:/Gzlkh/login.jsp
String url = request.getRequestURI();
// 此处截取的url为:login.jsp
url = url.substring(url.lastIndexOf("/") + 1, url.length());
try {
HttpSession session = request.getSession();
// 获取网站访问根目录
String accessPath = request.getContextPath();
// 获取用户登录验证信息
login st = (login) session.getAttribute("st");
if (noFileUrl(url, request)) {
// 不需要判断权限的请求如登录页面,则跳过
chain.doFilter(request, response);// 继续执行请求
} else if (st == null) {
response.sendRedirect(accessPath + "/login.jsp");
// 未登录或超时,返回登陆页面
} else {
verifyUrl(url, st);// 判断当前user是否拥有访问此url的权限
}
} catch (Exception sx) {
sx.printStackTrace();
}
}
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
转化一下,然后用httpServletRequest调用getparameter("参数"),getRequestURL() 方法
request.getRequestURL()
request.getRequestURL()、request.getRequestURI()
楼主派分吧 :)
request.getparameter("参数名");