在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ 求問(wèn):SpringBoot 2.0.3 通過(guò)編程方式整合jsp;jsp頁(yè)面沒(méi)有渲

求問(wèn):SpringBoot 2.0.3 通過(guò)編程方式整合jsp;jsp頁(yè)面沒(méi)有渲染而是直接返回整個(gè)頁(yè)面字符串

使用springBoot整合jsp,controller,mybatis都整合好了,但是在訪問(wèn)jsp頁(yè)面的時(shí)候發(fā)現(xiàn)頁(yè)面并沒(méi)有進(jìn)行渲染,而是直接返回了整個(gè)頁(yè)面字符串。

jsp頁(yè)面如下

clipboard.png

controller如下

@Controller
public class UserCtrl {

    @Autowired
    AccountService AccountService;

    @RequestMapping("/hello")
    public String home (HttpServletRequest request){
        Account account = AccountService.getAccountByName("Langdon");
        System.out.println(account.getAccountName());
        request.setAttribute("account",account);
        return "/helloworld";
    }
}

jsp對(duì)應(yīng)的ViewResolver bean;

已確定該路徑是生效的,如果注釋下面代碼會(huì)出現(xiàn)500異常.

    /**
     * JstlView
     */
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

訪問(wèn) http://localhost:8080/hello 結(jié)果如下

clipboard.png

從結(jié)果中可以看到頁(yè)面并沒(méi)有渲染
嘗試過(guò)在properties直接寫下面配置,但得到結(jié)果一樣。嘗試用別的瀏覽器訪問(wèn),得到的結(jié)果也一樣。

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

maven打包jar

 <packaging>jar</packaging>
    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/webapp</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

在filefox RESTClient請(qǐng)求

header如下


    Status Code: 200
    Accept-Ranges: bytes
    Content-Language: zh-CN
    Content-Length: 315
    Date: Sat, 16 Jun 2018 08:51:57 GMT
    ETag: W/"315-1529136546000"
    Last-Modified: Sat, 16 Jun 2018 08:09:06 GMT

body如下

<%@page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Helloworld</title>
</head>
<body>
<h1>hello ${account.accountName}</h1>
</body>
</html>
回答
編輯回答
小曖昧

經(jīng)過(guò)1天的奮戰(zhàn),看了很多springboot項(xiàng)目,終于找到原因;
maven配置問(wèn)題;

錯(cuò)誤配置如下:

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
            
        </dependency>

正確配置為

        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>compile</scope>
        </dependency>

附上maven.scope的用法;
maven.scope的用法

2017年10月12日 16:04