2011-03-02 67 views
0

我正在嘗試使用登錄頁面身份驗證創建應用程序。對於同樣的我添加<form-login-page>到web.xml中(如下所示)。我可以把表單登錄頁面html放在一個webapp的庫中嗎?

我打開了logon.html和logonerror.html,並將它們作爲庫與.war webapp文件一起添加。 (在WEB-INF/lib/logon.jar下)。

但是當我部署應用程序時,得到錯誤404,logon.html未找到錯誤。 任何指向爲什麼?我不能讓登錄文件(htmls,js,css文件)保存在一個庫中嗎?

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
     version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"> 
<filter> 
    <filter-name>MyFilter</filter-name> 
    <filter-class>MyFilter</filter-class> 
    <init-param> 
     <param-name>Domainname</param-name> 
     <param-value></param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>MyFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>SecuredResources</web-resource-name> 
     <url-pattern>/*</url-pattern>  
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>Default_Role</role-name> 
    </auth-constraint> 
     <user-data-constraint>    
     <transport-guarantee>CONF</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

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

    <security-role> 
    <role-name>Default_Role</role-name> 
    </security-role> 

</web-app> 

回答

2

我的理解是,WAR只會暴露其自身根文件結構中包含的資源。因此,在this question的答案中提到的解決方法(weblets,Maven配置)。你可以製作一個定製的構建腳本,將logon.jar的內容解壓縮到WAR中,但我絕對不會推薦這種破解。有了更多的信息爲什麼你想這樣做有人可能能夠提供更好的方法。

0

就我所知,html文件應該放在WAR而不是JAR中,因爲這些都是web資源。 JAR文件應該只包含您的Web組件(例如Servlet,JSP)使用類加載機制查找的類/資源。

相關問題