首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当将login.xhtml设置为我的主页时,它不工作

当将login.xhtml设置为我的主页时,它不工作
EN

Stack Overflow用户
提问于 2013-01-23 21:55:38
回答 1查看 2.2K关注 0票数 0

当我将我的login.xhtml页面设置为欢迎文件的web.xml时,它不工作,我的意思是它显示页面很好,但当我按下登录时什么也没有发生,但当我手动转到登录页面http://localhost:8080/fileuploadWithPreview/login.xhtml时,它工作得很好,你知道为什么吗?

web.xml:

代码语言:javascript
复制
       <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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_2_5.xsd">
    <filter>
        <filter-name>Upload Filter</filter-name>
        <filter-class>richard.fileupload.UploadFilter</filter-class>
        <init-param>
            <param-name>sizeThreshold</param-name>
            <param-value>1024</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Upload Filter</filter-name>
        <url-pattern>/faces/upload/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/corejsf.taglib.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>LDAP</realm-name>
        <form-login-config>
            <form-login-page>/login.xhtml</form-login-page>
            <form-error-page>/login-failed.xhtml</form-error-page>
        </form-login-config>
    </login-config>
    <security-role>
        <role-name>user</role-name>
    </security-role>
    <security-constraint>     
        <!-- web resources that are protected -->
        <web-resource-collection>
            <web-resource-name>All Resources</web-resource-name>
            <url-pattern>/*</url-pattern>
            <!-- this is currently causing a 404 -->
            <http-method>GETLIB</http-method>
            <http-method>COPY</http-method>
            <http-method>MOVE</http-method>
            <http-method>DELETE</http-method>
            <http-method>PROPFIND</http-method>
            <http-method>GET</http-method>
            <http-method>HEAD</http-method>
            <http-method>PUT</http-method>
            <http-method>MKCOL</http-method>
            <http-method>PROPPATCH</http-method>
            <http-method>LOCK</http-method>
            <http-method>UNLOCK</http-method>
            <http-method>VERSION-CONTROL</http-method>
            <http-method>CHECKIN</http-method>
            <http-method>CHECKOUT</http-method>
            <http-method>UNCHECKOUT</http-method>
            <http-method>REPORT</http-method>
            <http-method>UPDATE</http-method>
            <http-method>CANCELUPLOAD</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>*</role-name>
        </auth-constraint>
    </security-constraint>
</web-app>

当我按下登录按钮时,它会将我带回登录页面,但它已经对用户进行了身份验证,那么如何在登录按钮上让它在身份验证后转到index.html页面呢?

登录页面:

代码语言:javascript
复制
<div id="site_content">
    <div id="content">
        <h:body>
            <form method="post" action="j_security_check">
                <p>You need to log in to access protected information.</p>
                <table>
                    <tr>
                        <td>User name:</td>
                        <td><input type="text" name="j_username" /></td>
                    </tr>
                    <tr>
                        <td>Password:</td>
                        <td><input type="password" name="j_password" /></td>
                    </tr>
                </table>
                <p><input type="submit" value="Login" />

                    <!--<h:commandButton value="This will reset all the data " type="button" > </h:commandButton> -->
                    <input type="reset" name="Login-reset" value="Reset" onclick="alert('This will reset all the data');" />
                </p>
            </form>
        </h:body>
    </div>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-23 22:38:41

<url-pattern>/faces/*</url-pattern>替换为<url-pattern>*.xhtml</url-pattern>,并删除所有URL中的所有/faces/路径。通过这种方式,一切都应该按预期工作。

说明:<welcome-file>需要当前请求的文件夹(!)中实际存在的文件它应该是index.xhtmllogin.xhtml,并且<form-login-page>期望一个完全值得的URI,该URI应该是/faces/login.xhtml。当您为JSF使用文件夹映射时,这两者不能很好地混合。因此,只需将其映射到*.xhtml上,您就不必担心虚拟URL了。

另请参阅:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14481457

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档