0

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.

5
  • For one thing you need to get rid of the spaces around the "/" characters, both in the "href" and in the "type". Commented Aug 21, 2014 at 15:41
  • Aside from the </link> (which will be ignored), you do it like that. Commented Aug 21, 2014 at 15:43
  • This is a mistake of copy and paste. I've updated the question. Commented Aug 21, 2014 at 15:44
  • @django Spaces around the = matters. Remove that too! Commented Aug 21, 2014 at 15:45
  • Done! It doesn't work. Commented Aug 21, 2014 at 15:47

2 Answers 2

1

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:

enter image description here

and import like this:

 <link type="text/css"
          rel="stylesheet"
          href="${pageContext.request.contextPath}/resources/css/index.css">
Sign up to request clarification or add additional context in comments.

Comments

0

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" />

9 Comments

With ' <link href="css/login.css" type="text/css" rel="stylesheet" /> ' doesn't work.
Is the file css/login.css actually exist?
Yes, it is in css folder. @Praveen Kumar for this reason I can not see where the problem is.
Try opening it from the browser and let us know what's happening. It might even be a server fault!
Via the browser with this url: 'localhost:8080/ProjectName/css/login.css' it returns 404 error.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.