Gianlorenzo Didonato Gianlorenzo Didonato - 2 months ago 11
CSS Question

I can not load the CSS pages which can be accessed after a login carry with spring security. How can I fix it?

I should add CSS to two pages to which it is accessed after a login for which data are checked with spring security

How do I add CSS to these two pages protected with spring security?


<link rel="stylesheet" href="<c:url value=" resources/css/bootstrap.responsive.css" />" type="text/css">
<link rel="stylesheet" href="<c:url value=" resources/css/bootstrap.css" />" type="text/css">
<link rel="stylesheet" href="<c:url value=" resources/css/fontello-ie7.css" />" type="text/css">
<link rel="stylesheet" href="<c:url value=" resources/css/fontello.css" />" type="text/css">
<link rel="stylesheet" href="<c:url value=" resources/css/prettyPhoto.css" />" type="text/css">
<link rel="stylesheet" href="<c:url value=" resources/css/style.css" />" type="text/css">


<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />


<http auto-config="true">
<access-denied-handler error-page="/error" />
<intercept-url pattern="/admin**" access="ROLE_ADMIN" />
<intercept-url pattern="/utente**" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/role" authentication-failure-url="/login" />

<password-encoder hash="bcrypt" />
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password,TRUE from Student where username = ?"
authorities-by-username-query="select username,role from Student where username = ?" />

@RequestMapping(value="/role", method = RequestMethod.GET)
public String loginRole() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String role = auth.getAuthorities().toString();
String targetUrl = "";
if(role.contains("ROLE_USER")) {
targetUrl = "/users/task";
} else if(role.contains("ROLE_ADMIN")) {
targetUrl = "/administration/homeAdmin";
return targetUrl;

Sam Sam
<mvc:resources mapping="/resources/**" location="/resources/" />

According to above line,you should make sure that your css files is under location="/resources/"(resources folder).If they are present in some other folder make change location path.

And in spring-security.xml add below line so that for resources no security is required.

<http pattern="/resources/**" security="none"/> 

After that in jsp.

<link type="text/css" href="${pageContext.request.contextPath}/resources/css/fontello.css"  rel="stylesheet">