J888
J888

Reputation: 1964

How to log out using spring-security?

I am applying Spring-security on my struts2 application, it perfectly works but when I am in an address like following and click on logout it runs into following error,

 localhost/myProject/cons

Error

java.lang.NoSuchMethodException: com.myProject.controller.cons.j_spring_security_logout()

I can only logout successfully when I am in first page (index page) of the application. I reckon the problem is with my login link but not sure how to solve the issue.

security.xml

<logout logout-success-url="/index.jsp"/>

Logout link

 <a href="<c:url value="j_spring_security_logout" />" > Logout</a>

Upvotes: 1

Views: 505

Answers (2)

c f
c f

Reputation: 196

I faced this problem too. I forgot to add this to the top of my page.

 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 

So this is what the beginning of the page will look like,

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 


<!DOCTYPE html>
<html>

Upvotes: 0

Michael
Michael

Reputation: 10319

Use

<c:url value="/j_spring_security_logout" />

Upvotes: 3

Related Questions