2015-04-21 15 views
0

我正在學習過濾器。我使用netbens 8.02。無法從HTML頁面調用Java過濾器

我有一個silmple html頁面:

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
    <head> 
     <title>TODO supply a title</title> 
     <meta charset="UTF-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <link href="css/css.css" type="text/css" rel="stylesheet"/> 
    </head> 
    <body> 
     <nav> 
      <form action="f"> 
       <label for="username">User: </label><input name ="username" type="text"> 
       <label for="password">Password: </label><input name ="password" type="password"> 
       <input type="submit" value="Vai"> 
      </form> 
     </nav> 

     <section id ="page"> 

     </section> 
    </body> 
</html> 

而且我試圖調用一個名爲「F」的過濾器,但每次我構建並運行broject,我嘗試嘗試登錄後裝入過濾器我得到的404消息:

type Status report 

message /Filtri/f 

description The requested resource is not available. 

這是我的web.xml文件:(通過內置的NetBeans)

> <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" 
> xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
> http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
>  <filter> 
>   <filter-name>f</filter-name> 
>   <filter-class>f</filter-class> 
>  </filter> 
>  <filter-mapping> 
>   <filter-name>f</filter-name> 
>   <url-pattern>/*</url-pattern> 
>  </filter-mapping> 
>  <session-config> 
>   <session-timeout> 
>    30 
>   </session-timeout> 
>  </session-config> </web-app> 

這是我的項目階段:Project hierachy

你能幫助我嗎?

+1

您必須提及針對的完全限定類的過濾器 – Kartic

+0

另外還有一個通道:一個Servlet過濾器是一個可以攔截針對您的Web應用程序的HTTP請求的對象,您應該創建一個Servlet而不是Filter – Kartic

回答

2

Filter的攔截或預先處理的請求,但請求仍需要去一個資源(servlet,一個jsp,或html頁),否則,服務器將用404

您迴應請求的資源位於f,但雖然過濾器可能會攔截請求,但一旦過濾器完成處理,服務器仍然會嘗試將您發送至f,這不是您的上下文中的任何內容。