Spring Boot系列02-Spring Boot + JSP 整合进行网页开发
来源:互联网 发布:爱普生tx800清零软件 编辑:程序博客网 时间:2024/05/19 18:11
IDE创建Maven项目
MVC展示层模板Spring Boot官方不推荐使用JSP,
但是像我这有已经用惯了JSP,再换FreeMarker/Velocity学习成本有点大。
还用JSP,有两块需要注意的地方。
需要创建Maven web项目,在IDE中创建maven项目时,ArtifactId选maven-archtype-webapp
需要在src/main/resources目录下的核心配置文件application.properties中追加如下配置
application.properties
spring.mvc.view.prefix=/WEB-INF/views/spring.mvc.view.suffix=.jsp
最简单pom依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency> </dependencies>
JSP页面开发
新建源文件夹src/main/webapp
在src/main/webapp下创建WEB-INF/views文件夹
tt.jsp内容如下
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html><html lang="zh"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Full Layout - jQuery EasyUI Demo</title></head><body> <input type="button" value="点我" onclick="f()"/> <input type="text" style="height:100px;width:90%" id="input"/></body></html>
Java后端代码
driver.TesterMan.java
package driver;import java.util.Map;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@EnableAutoConfiguration@Controllerpublic class TesterMan{ public static void main(String[] args) throws Exception { SpringApplication.run(TesterMan.class, args); System.out.println("spring boot running ..."); } @RequestMapping("/tt") public String index(Map<String,Object> ){ return "/tt"; }}
测试
以java application运行程序
在浏览器访问localhost:8080/tt
看到一个按钮控件、一个文本框控件,说明Spring Boot + Jsp整合成功
阅读全文
0 0
- Spring Boot系列02-Spring Boot + JSP 整合进行网页开发
- [三]Spring Boot 整合jsp
- spring boot + mybatis + jsp整合
- 在Spring Boot 应用中使用JSP开发网页
- spring-boot整合Mock进行单元测试
- spring-boot系列——整合jersey
- Spring Boot系列(一):初识spring boot开发
- spring boot 整合Freemarker
- Spring Boot整合MyBatis
- spring-boot整合kindeditor
- spring boot 整合mybatis
- Spring Boot整合MyBatis
- Spring-boot整合Mybatis
- spring boot ehcache整合
- Spring Boot整合MyBatis
- spring boot 整合 CAS
- spring boot 整合mybatis
- spring-boot整合websocket
- C# 3DES 加密
- leetcode习题解答:11. Container With Most Water
- ssm框架搭建(主要配置步骤)
- 网站开发流程,个人心得,欢迎补充
- 【NOIP2017提高A组集训10.25】摘Galo (树形dp)
- Spring Boot系列02-Spring Boot + JSP 整合进行网页开发
- 初识网站安全
- flask-web开发-用户认证代码分析(四)
- 反射
- 互联网协议入门(一)
- 数字图像处理(第三版)—bmp图像的格式
- 大概整理下升级到Android Studio3.0遇到的问题
- linux centos7下QT5添加log4cplus库开发
- [线段树] HDU 3306