Reputation: 153
I have a folder called css
with inside login.css file.
At the same level as this folder, I have login.jsp file. How do I include external css in jsp page?
I tried with
<html>
<head>
<title> Login Page </title>
<link href ="css/login.css" type ="text/css" rel ="stylesheet"></link>
...
but it does not work.
If it can be useful in the top login.jsp page is written:
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
Thanks.
Upvotes: 0
Views: 6416
Reputation: 5106
I have this class
@Configuration
@EnableWebMvc
@ComponentScan("noughtsandcrosses")
public class DemoAppConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/pages/");
bean.setSuffix(".jsp");
return bean;
}
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
for this app structure:
and import like this:
<link type="text/css"
rel="stylesheet"
href="${pageContext.request.contextPath}/resources/css/index.css">
Upvotes: 1
Reputation: 167172
There's no </link>
tag! Replace like the below:
<link href="css/login.css" type="text/css" rel="stylesheet" />
Do not give spaces after and before the slashes. Also there's no </link>
tag! Replace the below:
</ title>
<link href = "css / login.css" type = "text / css" rel = "stylesheet"> </ link>
With the below:
</title>
<link href="css/login.css" type="text/css" rel="stylesheet" />
Upvotes: 0