我怎么才能从ServletRequest request 中的到URL,参数我能得到。 5
publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)thr...
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {}
HttpServletRequest 才有getparameter("参数"),getRequestURL() 方法。 展开
FilterChain chain) throws IOException, ServletException {}
HttpServletRequest 才有getparameter("参数"),getRequestURL() 方法。 展开
展开全部
给一个例子你,希望对你能有帮助
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();
}
}
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() 方法
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
转化一下,然后用httpServletRequest调用getparameter("参数"),getRequestURL() 方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getRequestURL()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getRequestURL()、request.getRequestURI()
楼主派分吧 :)
楼主派分吧 :)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.getparameter("参数名");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询