Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 Spring安全自定义表单总是失败_Jsf 2_Spring Security - Fatal编程技术网

Jsf 2 Spring安全自定义表单总是失败

Jsf 2 Spring安全自定义表单总是失败,jsf-2,spring-security,Jsf 2,Spring Security,我试图使用SpringSecurity为我的网站(使用JSF2创建)提供一个自定义登录。当我使用默认登录表单时,网站运行良好。但是,当我尝试使用自己的自定义登录表单时,即使键入了正确的用户名/密码,我也总是会被指向身份验证失败url。有人知道这是为什么,或者我如何解决它吗?我的代码如下 security-config.xml <?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns:sec="http://www.spr

我试图使用SpringSecurity为我的网站(使用JSF2创建)提供一个自定义登录。当我使用默认登录表单时,网站运行良好。但是,当我尝试使用自己的自定义登录表单时,即使键入了正确的用户名/密码,我也总是会被指向身份验证失败url。有人知道这是为什么,或者我如何解决它吗?我的代码如下

security-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/security
                http://www.springframework.org/schema/security/spring-security-3.1.xsd">

 <sec:http auto-config="true" use-expressions="true">
    <sec:intercept-url pattern="/login.jsf" access="isAnonymous()" />
    <sec:intercept-url pattern="/pages/secure/**" access="hasRole('ROLE_USER')" />
    <sec:intercept-url pattern="/pages/home/**" access="hasRole('ROLE_USER')" />
    <sec:intercept-url pattern="/pages/unsecure/**" access="permitAll"/>
    <sec:form-login login-page="/login.jsf" default-target-url="/pages/home/home.jsf"
                    authentication-failure-url="/fail.jsf"/>
</sec:http>

<sec:authentication-manager alias="authenticationManager">
    <sec:authentication-provider>
        <sec:user-service>
            <sec:user authorities="ROLE_USER" name="admin" password="admin" />
        </sec:user-service>
    </sec:authentication-provider>
</sec:authentication-manager> 
</beans:beans>

login.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<title>Login</title>
<h:outputStylesheet name="css/styles.css" />
<h:outputScript name="jquery/jquery-plugins.js" library="primefaces" />
</h:head>
<h:body>
<div class="login">
    <form method="POST" action="j_spring_security_check">
        <h:inputText name="j_username" id="username"></h:inputText>
        <p:watermark for="username" value="Username" />
        <br />  
        <h:inputSecret name="j_password" id="password">
        </h:inputSecret>
        <p:watermark for="password" value="Password" />
        <br />
        <h:commandButton name="submit" type="submit" value="Submit"></h:commandButton>
    </form>
</div>
</h:body>
</html>

登录



尝试将以下内容设置为表单的操作


action=“#{request.contextPath}/j_spring\u security\u check”

尝试将以下内容设置为表单的操作


action=“#{request.contextPath}/j#u spring\u security\u check”

您看过生成的HTML输出了吗?在浏览器中右键单击页面,不查看源代码即可查看该页面

名称
属性

<h:inputText name="j_username" id="username"></h:inputText>
<h:inputSecret name="j_password" id="password"></h:inputSecret>
当然,您也可以只使用普通的HTML:

<input type="text" name="j_username" placeholder="Username" />
<input type="password" name="j_password" placeholder="Password" />

您是否查看了生成的HTML输出?在浏览器中右键单击页面,不查看源代码即可查看该页面

名称
属性

<h:inputText name="j_username" id="username"></h:inputText>
<h:inputSecret name="j_password" id="password"></h:inputSecret>
当然,您也可以只使用普通的HTML:

<input type="text" name="j_username" placeholder="Username" />
<input type="password" name="j_password" placeholder="Password" />


Opps。我忘了h:inputText不等于输入。非常感谢!啊。我忘了h:inputText不等于输入。非常感谢!