2014-01-26 34 views
0

我遇到了具有兩個選項卡 - 登錄/註冊的安全表單。 在添加寄存器選項卡之前它工作。我正在使用彈簧安全。 這甚至可能嗎? 下面是代碼的一部分: JSP: 的index.jsp可以用彈簧安全保護選項卡式表格

<div id="dialog"> 
    <form id="dialogForm" action="j_spring_security_check" method="GET"> 
     <div id="tabs"> 
      <ul> 
       <li><a href="#login">Login</a></li> 
       <li><a href="#register">Register</a></li> 
      </ul> 
      <div id="login"> 
       <jsp:include page="login.jsp"/> 
      </div> 
      <div id="register"> 
       <jsp:include page="register.jsp"/> 
      </div> 
     </div> 
    </form> 
</div> 

的login.jsp

<form:form id="logingForm" action="login" method="GET"> 
    <div id="loginForm" class="ui-widget-content" > 
      <table> 
      <tr> 
       <td align="right" width="100">User:</td> 
       <td width="100"><input type="text" name="j_username"/></td> 
      </tr> 
      <tr> 
       <td align="right" width="100">Password:</td> 
       <td width="100"><input type="password" name="j_password" /></td> 
      </tr> 
      </table> 
      <br> 
      <input id="logInButton" type="submit" value="SignIn" /> 
    </div> 
</form:form> 

register.jsp

<form:form id="mainRegForm" action="register" commandName="registration" method="GET"> 
    <table align="right" width="300" cellpadding="0"> 
      <tr> 
       <td>User Name:<FONT color="red"><form:errors 
       path="userName" /></FONT></td> 
       <td><form:input path="userName" /></td> 
      </tr> 
      <tr> 
       <td>Password:<FONT color="red"><form:errors 
       path="password" /></FONT></td> 
       <td><form:password path="password" /></td> 
      </tr> 
      <tr> 
       <td>Confirm Password:<FONT color="red"><form:errors 
       path="confirmPassword" /></FONT></td> 
       <td><form:password path="confirmPassword" /></td> 
      </tr> 
      <tr> 
      <tr> 
       <td>Email address:<FONT color="red"><form:errors path="email" /></FONT></td> 
       <td><form:input path="email" /></td> 
      </tr> 
      <tr> 
       <td>Age:<FONT color="red"><form:errors path="age" size="1" /></FONT></td> 
       <td><form:select path="age" items="${ageList}"/></td> 
      </tr> 
      <tr> 
       <td>Sex:<FONT color="red"><form:errors path="sex" size="1" /></FONT></td> 
       <td><form:select path="sex" items="${mfList}"/></td> 
      </tr> 
      <tr> 
       <td>Location:<FONT color="red"><form:errors path="location" size="1" /></FONT></td> 
       <td><form:select path="location" items="${countryList}"/></td> 
      </tr> 
      <tr> 
       <td><input type="submit" value="Register" onClick="submitRegister()"/></td> 
      </tr> 
    </table> 
</form:form>  

彈簧的security.xml

<http auto-config="true"> 
    <form-login login-page="/index" default-target-url="/welcome" 
     authentication-failure-url="/loginfailed" /> 
    <logout logout-success-url="/logout" /> 
</http> 

<authentication-manager> 
    <authentication-provider user-service-ref="customUserDetailsService"> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="customUserDetailsService" class="controllers.CustomUserDetailsService"> 
    <beans:property name="userDao" ref="userDao"/> 
</beans:bean> 

當我按下登錄按鈕提交選項卡式對話框時,它將我重定向到登錄失敗的頁面。我嘗試初始化CustomUserDetailsS​​ervice類,但未執行。 你能幫我解決這個問題嗎? 謝謝指教!

+0

你有任何日誌? –

+0

沒有。沒有錯誤或一些警告。 – user2883938

+0

您是否嘗試過從UsernamePasswordAuthenticationFilter.attemptAuthentication()開始進行調試? –

回答

0

包括<jsp:include page="login.jsp"/><jsp:include page="register.jsp"/>嵌套在窗體內 - 這是不是有效的HTML。瀏覽器可能無法傳輸您期望的內容 - 因此登錄失敗的頁面。

你應該刪除index.jsp聲明外,然後編輯login.jsp和更改logingForm動作要j_spring_security_check

+0

它是一樣的。不工作。有趣的是,當我點擊register.jsp中的註冊按鈕時,它會工作,並且我成功地將新用戶添加到數據庫。它的登錄,我有這個問題。 – user2883938

+0

除了將'logingForm'的操作更改爲'j_spring_security_check' - 嘗試將表單更改爲普通HTML'

'元素而非Spring的''標籤。 –

+0

我將表格形式更改爲,但注意到會發生。如果我從登錄jsp中移除表單並將其放在中,它會有效嗎? – user2883938