图解在Spring Boot中使用JSP页面的方法

发布时间:2020-07-11 10:39:31 作者:清晨
来源:亿速云 阅读:527

小编给大家分享一下图解在Spring Boot中使用JSP页面的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

一、创建webapp目录

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

图解在Spring Boot中使用JSP页面的方法

二、创建jsp

1、指定web资源目录

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

图解在Spring Boot中使用JSP页面的方法

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

图解在Spring Boot中使用JSP页面的方法

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

图解在Spring Boot中使用JSP页面的方法

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

图解在Spring Boot中使用JSP页面的方法

图解在Spring Boot中使用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

图解在Spring Boot中使用JSP页面的方法

五、逻辑视图配置

图解在Spring Boot中使用JSP页面的方法

六、访问

图解在Spring Boot中使用JSP页面的方法

图解在Spring Boot中使用JSP页面的方法

看完了这篇文章,相信你对图解在Spring Boot中使用JSP页面的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. Spring Boot实践——SpringMVC视图解析
  2. spring boot 入门一

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

spring boot jsp

上一篇:php错误显示配置怎么办

下一篇:Spring Boot集成Mybatis中显示日志的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》