Java Servlet 过滤器 - 错误 404 - 未从 RFC 2068 超文本传输​​协议中找到 - HTTP/1.1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22318682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:55:32  来源:igfitidea点击:

Servlet Filter - Error 404--Not Found From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1

javaservletsweb-applicationsservlet-filtersweblogic11g

提问by user1251490

iam using the below code in servlet filters to avoid direct acess of pages from the URL but i get Error 404--Not Found - From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1irrespective of the URL i try.

我在 servlet 过滤器中使用以下代码来避免从 URL 直接访问页面,但我收到错误 404--未找到-来自 RFC 2068 超文本传输​​协议 -- HTTP/1.1,而不管我尝试的 URL。

Code:

代码:

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    String uri = req.getRequestURI();
    this.context.log("Requested Resource::"+uri);

    HttpSession session = req.getSession(false);
    if(session == null && !(uri.endsWith("html") || uri.endsWith("LoginServlet"))){
        this.context.log("Unauthorized access request");
        res.sendRedirect("login.html");
    }else{
        // pass the request along the filter chain
        chain.doFilter(request, response);
    }   

}

My Web.xml

我的网页.xml

    <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
 <web-app>
 <display-name>ServletFilterExample</display-name>
 <filter>
<filter-name>RequestLoggingFilter</filter-name>
<filter-class>com.journaldev.servlet.filters.RequestLoggingFilter</filter-class>
</filter>
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>com.journaldev.servlet.filters.AuthenticationFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>RequestLoggingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
 </web-app>

Environment used: Weblogic server 11gR1 and web app 2.5

使用环境:Weblogic server 11gR1 和 web app 2.5

I'm Hitting the url :

我正在点击网址:

http://localhost:7001/Filters/LoginServlet

Could you please help.

能否请你帮忙。

Thanks.

谢谢。

回答by Keerthivasan

I strongly recommend you to check whether you are application is properly deployed in your server. I see that the configurations in web.xml are fine, mapped with filters properly with URL. Please double check it.

我强烈建议您检查您的应用程序是否正确部署在您的服务器中。我看到 web.xml 中的配置很好,用 URL 正确映射了过滤器。请仔细检查。