简介:
springboot默认使用thymeleaf模版引擎,不推荐使用jsp,但是,有什么办法呢?总要一步步来。先整合一波压压惊。其实遇到一系列idea操作问题。
创建好子模块spring-boot-jsp
创建webapp文件夹及子目录。
发现创建不了jsp,没有这个选项。webapp上面没有这个蓝点。
增加依赖
<!--servlet的支持-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- 开启对jsp的支持 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!--jstl-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
项目设置web模块
ctrl + shift + alt + s 打开项目配置
设置webapp为web资源路径右键就可以创建jsp文件了。
如果没有web模块可以选,那就点绿色的加号,添加一下web模块可以了。web.xml如果有的话就把上面的的Path设置为web.xml。没有也没关系。
然后就建立一个jsp页面,页面随便写点上面确认一下就好了。
创建一个控制器页面跳转一波
@Controller
public class Index {
@RequestMapping("/jsp")
public String index() {
System.out.println("进入到jsp");
return "index";
}
}
启动
注意这里启动是使用maven命令来启动
页面访问http://localhost:8080/jsp 即可。
很多idea直接运行main访问报404、Whitelabel Error Page,具体原因,请听下回分解!