欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

图解如何在Spring Boot中使用JSP页面

时间:2021-05-01 09:35:24|栏目:JAVA代码|点击:

一、创建webapp目录

在src/main下创建webapp目录,用于存放jsp文件。这就是一个普通的目录,无需执行Mark Directory As

二、创建jsp

1、指定web资源目录

在spring boot工程中若要创建jsp文件,一般是需要在src/main下创建webapp目录,然后在该目录下创建jsp文件。但通过Alt + Insert发现没有创建jsp文件的选项。此时,需要打开Project Structrue窗口,将webapp目录指定为web资源目录,然后才可以创建jsp文件。

指定后便可看到下面的窗口情况。

此时,便可在webapp中找到jsp的创建选项了。


2、创建index.jsp页面与welcome.jsp页面

三、添加jasper依赖

在pom中添加一个Tomcat内嵌的jsp引擎jasper依赖。

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

四、注册资源目录

在pom文件中将webapp目录注册为资源目录

<build>
	<resources>
		<!--注册webapp目录为资源目录-->
		<resource>
			<directory>src/main/webapp</directory>
			<targetPath>META-INF/resources</targetPath>
			<includes>
				<include>**/*.*</include>
			</includes>
		</resource>
	</resources>
 
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>

不过,我们一般会添加两个资源目录:

<resources>
	<!--注册Dao包目录下Mybatis映射文件资源目录-->
	<resource>
		<directory>src/main/java</directory>
		<includes>
			<include>**/*.xml</include>
		</includes>
	</resource>
 
	<!--注册webapp目录为资源目录-->
	<resource>
		<directory>src/main/webapp</directory>
		<targetPath>META-INF/resources</targetPath>
		<includes>
			<include>**/*.*</include>
		</includes>
	</resource>
</resources>

四、创建Controller

五、逻辑视图配置

六、访问

上一篇:批量上传Jar包到Maven私服的工具的方法

栏    目:JAVA代码

下一篇:Jenkins集成SonarQube的方法详解

本文标题:图解如何在Spring Boot中使用JSP页面

本文地址:http://www.codeinn.net/misctech/112750.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有