JSP在春天不渲染

时间:2016-04-15 08:55:38

标签: spring jsp

我的问题有类似的问题,但是他们说我必须添加像org.apache.tomcat.embed这样的依赖关系:tomcat-embed-jasper我做了,但是jsp还没有渲染?

输出:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>home</title>
</head>
<body>
home
</body>
</html>

预期产出:

home

WebConfig.java

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.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan("com.josip.controllers")
public class WebConfig extends WebMvcConfigurerAdapter {

    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        resolver.setExposeContextBeansAsAttributes(true);
        return resolver;
    } 

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}

的build.gradle

buildscript {
    ext {
        springBootVersion = '1.3.3.RELEASE'
    }
    repositories {
        maven { url 'http://repo.spring.io/plugins-release' }
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    }
}

configurations {
    jasper
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot' 

jar {
    baseName = 'HeadHunting'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.projectlombok:lombok:1.16.6')
    compile('org.springframework.boot:spring-boot-starter-web')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
    providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper")

    runtime('javax.servlet:jstl:1.2')

    runtime('org.postgresql:postgresql')
}


task wrapper(type: Wrapper) {
    gradleVersion = '2.12'
}

0 个答案:

没有答案