美文网首页
springboot 配置jsp

springboot 配置jsp

作者: _郭帅 | 来源:发表于2018-03-19 11:00 被阅读0次

springboot 本身是不支持jsp的,但是我们可以让它支持,步骤如下

步骤

  1. 创建 springboot war包项目
  2. 在 main 下创建 webapp 目录,默认是没有的
  3. 引入额外的依赖支持
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
    //如果下面这个依赖不添加,会出现解析不了 jsp,而直接下载的情况
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
  1. 配置 springmvc 返回 jsp 支持
spring:
  mvc:
    view:
      prefix: /views/
      suffix: .jsp
  1. 写 Controller 返回 jsp 页面
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
@Controller
public class XihaApplication {

    @RequestMapping(value = "/")
    public String index() {
        return "index";
    }

    public static void main(String[] args) {
        SpringApplication.run(XihaApplication.class, args);
    }
}

  1. 启动,访问的时候不能使用默认的方式。要使用maven 的命令 springboot.run

相关文章

网友评论

      本文标题:springboot 配置jsp

      本文链接:https://www.haomeiwen.com/subject/qtbuqftx.html