如何在jsp页面中包含外部css?

时间:2014-08-21 15:39:20

标签: javascript jsp

我有一个名为css的文件夹,里面有login.css文件。 在与此文件夹相同的级别,我有login.jsp文件。如何在jsp页面中包含外部css?

我试过

<html>
<head>
<title> Login Page </title>
         <link href ="css/login.css" type ="text/css" rel ="stylesheet"></link>
...

但它不起作用。

如果它在顶部login.jsp页面中有用,请写:

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>

感谢。

2 个答案:

答案 0 :(得分:0)

没有</link>标签!替换如下:

<link href="css/login.css" type="text/css" rel="stylesheet" />

不要在斜杠之前和之前给出空格。也没有</link>标签!替换下面的内容:

</ title>
         <link href = "css / login.css" type = "text / css" rel = "stylesheet"> </ link>

以下内容:

</title>
         <link href="css/login.css" type="text/css" rel="stylesheet" />

答案 1 :(得分:0)

我有这堂课

@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/");
    }
}

此应用程序结构:

enter image description here

并这样导入:

 <link type="text/css"
          rel="stylesheet"
          href="${pageContext.request.contextPath}/resources/css/index.css">
相关问题