I'm struggling to create a basic web page using JSP. The issue I'm facing is that no resources, such as images or CSS, are being found regardless of the URL I use.
Here is my simple JSP code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="SHORTCUT ICON" href="img/logo.ico" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div id="banner">
<div id="banner-wrapper">
<div id="appname">
<a href="" >
<img alt="logo-cloudapi" height="50px" src="/logo.png">
</a>
ABC
</div>
<div id="a">
<img alt="logo2" height="50px" src="/logo2.jpg">
</div>
</div>
</div>
</body>
I've tried different URLs:
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
None of them seem to work.
This is the structure of my src folder:
I am not using web.xml but rather Java config files.
Configuration:
package com.websystique.springmvc.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.websystique.springmvc")
public class HelloWorldConfiguration {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
Initializer
package com.orange.paddock.gofr.provider.ihm.configuration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class HelloWorldInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { HelloWorldConfiguration.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
I have come across several threads discussing similar issues, but none of the solutions provided have worked for me.
Any ideas on what could be the solution?