requestUri
时间: 2023-08-25 17:09:03 浏览: 54
requestUri是指请求的URI,即请求的路径。在Java EE中,可以使用HttpServletRequest对象的getRequestURI()方法来获取requestUri。例如,如果请求的URL是"http://example.com/servlet/RequestDemo1",那么requestUri就是"/servlet/RequestDemo1"。
相关问题
http协议Request URI
HTTP协议的Request URI指的是HTTP请求中的统一资源标识符。它包含了三部分内容:协议名、主机名以及资源路径。其中协议名和主机名之间用“://”隔开,主机名和资源路径之间用“/”隔开。
例如,在URL https://www.example.com/index.html 中,协议名为“https”,主机名为“www.example.com”,资源路径为“/index.html”。
在HTTP请求中,Request URI用于指定客户端想要访问的资源。服务器根据Request URI中指定的资源路径来确定需要返回的资源内容。此外,Request URI还可以包含查询参数,用于向服务器传递附加信息。
public class BaseFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { // 初始化 } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String requestURI = httpRequest.getRequestURI(); if (requestURI.endsWith("load.jsp") || requestURI.endsWith("load.action")) { // 如果是load.jsp或load.action请求,则直接放行 chain.doFilter(request, response); return; } HttpSession session = httpRequest.getSession(false); if (session != null && session.getAttribute("user") != null) { // 如果已经登录,则放行请求 chain.doFilter(request, response); return; } // 否则跳转到登录页面 httpResponse.sendRedirect("/load.jsp"); } @Override public void destroy() { // 销毁 } }补全代码
这段代码是一个基础的过滤器实现,用于过滤所有的请求,检查用户是否已经登录,如果没有登录则跳转到登录页面。
完整的代码如下:
```
public class BaseFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// 初始化
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String requestURI = httpRequest.getRequestURI();
if (requestURI.endsWith("load.jsp") || requestURI.endsWith("load.action")) {
// 如果是load.jsp或load.action请求,则直接放行
chain.doFilter(request, response);
return;
}
HttpSession session = httpRequest.getSession(false);
if (session != null && session.getAttribute("user") != null) {
// 如果已经登录,则放行请求
chain.doFilter(request, response);
return;
}
// 否则跳转到登录页面
httpResponse.sendRedirect("/load.jsp");
}
@Override
public void destroy() {
// 销毁
}
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)