This is a duplicated question: I found the solution here.
Where do CSS and JavaScript files go in a Maven web app project?
but instead doing it on xml as @Viriato said,
Just to clarify this is what I had to do:
Make sure that in your servlet-context.xml you have as follows:
<resources mapping="/resources/**" location="/resources/" />
,
create a folder if does not already exist under webapps called resources,
place your css folder along with css files there,
reference my css file as follows:
<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/960.css"/>
I decided to do a java based configuration because I already had my Config.java
class.
So, I extended my Config.java
class to the abstract class WebMvcConfigurerAdapter in order to use the method addResourceHandlers (which you have to Override if you want to use it)
This is what I had to do:
public class Config extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
...
}
Then I had to add the contextpath to my routes:
<script type="text/javascript" src="http://localhost:8585/electronicaDonPepe/resources/js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="http://localhost:8585/electronicaDonPepe/resources/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://localhost:8585/electronicaDonPepe/resources/js/angular.min.js"></script>
<link href="http://localhost:8585/electronicaDonPepe/resources/css/bootstrap.min.css" rel="stylesheet" />
If you don't know your context path you can use Scriptlets
like this:
<%= request.getContextPath() %>
As an example, the code for bootstrap.min.css will be:
<link href="<%= request.getContextPath() %>/resources/css/bootstrap.min.css" rel="stylesheet" />
If you want to know more about scriptlets you can read this: http://docs.oracle.com/javaee/5/tutorial/doc/bnaou.html
I'm planning to work with Angular
so hardcoded routes works for me by now, I don't encourage to do this because this is a bad practice. The user shouldn't be able to see your resources routes and mess around with them.
Thanks for your time.