java - Including css and javascript files in spring 4 project -


i'm making web app using spring 4, spring security module , tomcat 8. i'm trying include css files , js files in .jsp file, it's not working. when check in sources tag in chrome content of css seems log in form. suspect may have spring security.

my css file included in .jsp

<link href="<c:url value='resources/css/materialize.min.css' />" rel="stylesheet"         type="text/css"></link> 

this webconfig file

@configuration @componentscan(basepackages = "mypackage") @enablewebmvc @enabletransactionmanagement public class webappconfig extends webmvcconfigureradapter {     @bean     public internalresourceviewresolver viewresolver(){         internalresourceviewresolver resolver = new internalresourceviewresolver();         resolver.setprefix("/web-inf/views/");           resolver.setsuffix(".jsp");           resolver.setviewclass(jstlview.class);           return resolver;       }     @autowired     @bean     public hibernatetransactionmanager transactionmanager(sessionfactory sessionfactory){         hibernatetransactionmanager transactionmanager = new   hibernatetransactionmanager(sessionfactory);         return transactionmanager;     }     @override     public void addresourcehandlers(resourcehandlerregistry registry) {     registry.addresourcehandler("/resources/**").addresourcelocations("/resources/");     }     @override     public void configuredefaultservlethandling(defaultservlethandlerconfigurer configurer) {         configurer.enable();     } } 

this securityconfig file

public class securityconfig extends websecurityconfigureradapter {     ...      @override     public void configure(websecurity web) throws exception {         web.ignoring().antmatchers("/resources/js/**", "/resources/css/**", "/resources/img/**", "/resources/font/**");     }        @override     protected void configure(httpsecurity http) throws exception {         http.formlogin().loginpage("/signin")             .failureurl("/signin?param.error=bad_credentials")         .and().logout().logouturl("/signout")         .and().authorizerequests()                 .antmatchers("/favicon.ico", "/resources/css/**", "/resources/font/**",                         "/resources/js/**", "/auth/**", "/signin/**", "/signup/**", "/disconnect/facebook").permitall()                 .antmatchers("/**").authenticated()         .and()             .rememberme().         and().csrf();     } } 

according other answers here in stackoverflow should work code have css returns this:

 <!doctype html>  <html xmlns:th="http://www.thymeleaf.org"   xmlns:social="http://spring.io/springsocial"   xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"   layout:decorator="layout">      <head>      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">      <title>insert title here</title>      </head>      <body>     <div id="content" >         <form id="signin" action="signup" method="post">             <input type="hidden" name="" value=""/>             <div class="forminfo">              </div>             <fieldset>                 <label for="login">email</label>                 <input id="login" name="email" type="text" size="25"></input>                 <label for="nombre">email</label>                 <input id="nombre" name="nombre" type="text" size="25"></input>                 <label for="password">password</label>                 <input id="password" name="contrasena" type="password" size="25"></input>             </fieldset>             <button type="submit">sign in</button>               <p>or can <a href="signin">signin</a> new account.</p>         </form>     </div> 

all css , js files inside webcontent/resources

i solved problem, apparently there ambiguous routing in 1 of controllers, when tried access url started "/resources" routed controller, , returned .jsp instead of css/js/image. original controller binded url in @controller, , left @requestmapping without indicating route.

@controller("/signup") public class signupcontroller {     @requestmapping(method=requestmethod.get)     public string signupform(){         ...     }     @requestmapping(method=requestmethod.post)     public string crearusuario(httpservletrequest request){         ...     } 

so changed @controller annotation, , put url in each @requestmapping this:

@controller public class signupcontroller {     @requestmapping(value="/signup", method=requestmethod.get)     public string signupform(){}     @requestmapping(value="/signup",method=requestmethod.post)     public string crearusuario(httpservletrequest request){} } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -