2013-05-21 65 views
4

我的網絡應用程序出現此問題,我通過Tomcat執行基於表單的身份驗證,它將我重定向到徽標圖像文件而不是重定向到index.html文件它包含了標誌圖像...登錄後Tomcat重定向到錯誤的網址

我要去:

http://localhost:8080/GenTreeUploader/Servlet 

然後它給我的登錄表單,併成功登錄後,我沒有在該網址我去,但我被重定向到:

http://localhost:8080/GenTreeUploader/images/gdia_logo.png 

當我去我驗證後:

http://localhost:8080/GenTreeUploader/Servlet 

我然後重定向托特他正確的位置,而不是圖像文件。

我附上我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

    <!-- WELCOME FILE LIST --> 
    <welcome-file-list> 
     <welcome-file>/Servlet</welcome-file> 
    </welcome-file-list> 

    <!-- Security --> 

    <security-constraint> 

     <web-resource-collection> 
      <web-resource-name>Wildcard means whole app requires authentication</web-resource-name> 
      <url-pattern>/*</url-pattern> 
      <http-method>GET</http-method> 
      <http-method>POST</http-method> 
     </web-resource-collection> 

     <auth-constraint> 
      <role-name>tomcat</role-name> 
     </auth-constraint> 

     <user-data-constraint> 
      <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE --> 
      <transport-guarantee>NONE</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 

    <login-config> 
     <auth-method>FORM</auth-method> 
     <form-login-config> 
      <form-login-page>/login.jsp</form-login-page> 
      <form-error-page>/error.html</form-error-page> 
     </form-login-config> 
    </login-config> 

    <!-- Main Servlet --> 
    <servlet> 
     <servlet-name>GenTreeUploaderServlet</servlet-name> 
     <servlet-class>org.ktu.gdia.presentation.web.GenTreeUploader</servlet-class> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>GenTreeUploaderServlet</servlet-name> 
     <url-pattern>/Servlet</url-pattern> 
    </servlet-mapping> 


    <session-config> 
     <session-timeout> 
      60 
     </session-timeout> 
    </session-config> 
</web-app> 

嘛?任何想法爲什麼它不能按預期工作?提前致謝。

+0

看起來問題出在你的Servlet代碼或其他你沒有提供來分析和幫助你的地方。 –

回答

5

重定向實際上發生的事情,因爲那些被要求在登錄文件資源得到切實維護,因爲我已經選擇了整個路徑作爲安全資源:

<web-resource-collection> 
     <web-resource-name>Wildcard means whole app requires authentication</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
    </web-resource-collection> 

所以我創建了一個新的文件夾,名爲「Admin」並移動了需要在那裏保護的文件,並修改了servlet的路徑。這是我目前(固定)web.xml中的樣子:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 

    <!-- WELCOME FILE LIST --> 
    <welcome-file-list> 
     <welcome-file>Admin/Servlet</welcome-file> 
    </welcome-file-list> 

    <!-- Security --> 

    <security-constraint> 

     <web-resource-collection> 
      <web-resource-name>Wildcard means whole app requires authentication</web-resource-name> 
      <url-pattern>/Admin/*</url-pattern> 
      <http-method>GET</http-method> 
      <http-method>POST</http-method> 
     </web-resource-collection> 

     <auth-constraint> 
      <role-name>admin</role-name> 
     </auth-constraint> 

     <user-data-constraint> 
      <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE --> 
      <transport-guarantee>NONE</transport-guarantee> 
     </user-data-constraint> 
    </security-constraint> 

    <login-config> 
     <auth-method>FORM</auth-method> 
     <form-login-config> 
      <form-login-page>/login.jsp</form-login-page> 
      <form-error-page>/error.html</form-error-page> 
     </form-login-config> 
    </login-config> 

    <!-- Main Servlet --> 
    <servlet> 
     <servlet-name>GenTreeUploaderServlet</servlet-name> 
     <servlet-class>org.ktu.gdia.presentation.web.GenTreeUploader</servlet-class> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>GenTreeUploaderServlet</servlet-name> 
     <url-pattern>/Admin/Servlet</url-pattern> 
    </servlet-mapping> 


    <session-config> 
     <session-timeout> 
      60 
     </session-timeout> 
    </session-config> 
</web-app> 

所以現在的Tomcat不會重定向我到的圖像或CSS文件中記錄了之後,因爲他們現在成了acessible到未經認證。

+0

奇怪的是,如果我使用 Confidential它不起作用 – pokeRex110