springboot跳转jsp页面
springboot支持jsp页面跳转
官方不推荐jsp的支持(jar包不支持jsp,jsp需要运行在servletContext中,war包需要运行在server服务器中如tomcat)官方推荐使用thymeleaf,freemarker等模版引擎
1.创建maven project项目
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.woms.www</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <parent>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tomcat支持 -->
<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>
<!-- jsp标签库 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这里要注意的主要是引入tomcat支持和jstl标签库
2.application.properties配置文件
#springmvc
spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp
3.创建启动类和controller测试
package com.woms; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; //该@SpringBootApplication注解等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan。 @SpringBootApplication
public class StringbootApplication { public static void main(String[] args) {
// TODO Auto-generated method stub SpringApplication.run(StringbootApplication.class, args); } }
package com.woms.controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; //@RestController
@Controller
@RequestMapping("/login")
public class UserController { // @RestController相当于@Controller+@ResponseBody(每一个方法上默认返回的是json串) @RequestMapping("/initLogin")
public String initLogin(Model model){ model.addAttribute("model", "model:你被支持吗?");
return "hello"; } @RequestMapping("/")
public String welcome(){ return "index"; }
}
参考官方有个sample,地址是:
https://github.com/spring-projects/spring-boot/tree/v1.1.5.RELEASE
里面有个spring-boot\spring-boot-samples\spring-boot-sample-web-jsp自己跑一下。
springboot打包在linux服务器中运行
如果项目是应用服务,可以将项目设置成jar项目,打包成jar包直接运行
如果项目是web服务,将项目设置成war项目,打包成war包在tomcat环境下运行
1.打包插件
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
在eclipse可以用maven命令package直接打包,打包成jar包或者war包
jar包可以直接运行:java -jar xxx.jar war包需要放在tomcat下运行
用上面的方式启动springboot的web项目可以像启动应用项目一样通过main方法启动并访问jsp页面(适合开发),但是在linux中要打包成war包放在tomcat中运行
2.打包成war项目在tomcat中运行
2.1修改启动入口
package com.woms; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer; //该@SpringBootApplication注解等价于以默认属性使用@Configuration,@EnableAutoConfiguration和@ComponentScan。 @SpringBootApplication
public class MyApplication extends SpringBootServletInitializer { @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// TODO Auto-generated method stub
return builder.sources(MyApplication.class);
} }
2.2修改pom.xml文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
将内嵌的tomcat移除
如果是开发阶段的话,没有wen.xml是没法加入到tomcat服务器中的
需要注意一下几点:
1.jar包中的打包方式根据自己的需要进行修改
2.若打包成war包,则需要继承 org.springframework.boot.context.web.SpringBootServletInitializer类,覆盖其config(SpringApplicationBuilder)方法
3.打包成war的话,如果打包之后的文件中没有web.xml文件的话自己可以加进去一个最简单的web.xml(只有根节点的定义,而没有子元素),防止因缺乏web.xml文件而部署失败
总结:
1.web项目用maven创建war项目应用项目用maven创建jar项目
2.打包如果是war项目就打包成war包,放在tomcat下运行,如果是jar项目就打包成jar包 java -jar xxx.jar运行(用打包插件打包)
3.在开发阶段,jar项目可以通过main方法直接运行,war项目也可以通过main方法直接运行,需要修改pom.xml文件和springboot入口
springboot跳转jsp页面的更多相关文章
- springboot 2.0.8 跳转jsp页面
springboot项目创建教程 https://blog.csdn.net/q18771811872/article/details/88126835 springboot 2.0跳转 html教程 ...
- 分享url带中文参数,打开html操作完毕跳转jsp页面中文乱码解决
1.在app端分享参数组合时不对传递的url进行任何编码. 2.打开html页面时使用 escape函数对有中文的参数进行编码 escape(GetQueryString("paramete ...
- SpringBoot配置使用jsp页面技术
SpringBoot配置使用jsp页面技术 1.pom配置 package配置必须为war类型 添加依赖 <packaging>war</packaging> <depe ...
- Springboot+MyBatis+mysql+jsp页面跳转详细示例
SpringBoot与MyBatis搭建环境,底层数据库为mysql,页面使用JSP(官网上不推荐使用jsp),完成从数据库中查询出数据,在jsp页面中显示,并且实现页面的跳转功能. 项 ...
- SpringBoot启动访问JSP页面,直接进入页面或者访问不到,报404,并且加载tomcat插件tomcat-embed-jasper也不行
这个问题花费了两天的时间,解决路径: 我用的是SpringBoot1.5.2,SpringMVC和Spring,tomcat启动插件都是默认的版本,Spring是4.3.7,jdk是1.7.0_80, ...
- springboot配置对jsp页面的解析支持
pom.xml文件配置依赖信息 <!--引入Spring Boot内嵌的Tomcat对JSP的解析包,不加解析不了jsp页面--> <dependency> <group ...
- springboot 自定义错误jsp页面
1.总览 2.application.properties spring.mvc.view.prefix=/WEB-INF/pages/ spring.mvc.view.suffix=.jsp#关闭w ...
- springboot 运行jar 跳转jsp页面
pom.xml 添加 <!-- tomcat支持 --> <dependency> <groupId>org.springframework.boot</gr ...
- springboot+jsp+mybatis项目实例(后台成功,但是无法跳转jsp页面,没有实体类的注解,看springboot+jsp第二弹相关配置,即可成功配置jsp)
SpringBoot是用来简化SpringMvc开发的项目,这里自然要整合mybatis等持久化框架! 先看看项目目录: 一.在pom.xml中配置依赖jar包:<project xmlns=& ...
随机推荐
- git---小乌龟提交
下载地址:https://tortoisegit.org/ 比如我修改了文件: 1.本地提交在项目目录内右键,点击git commit按钮 2.拉去线上最新代码,与本地代码合并 3.向线上推送
- MySQL 温故知心(三)
MySQL锁概述 相对其他数据库而言,MySQL的锁机制比较简单,其最显著的特点是不同的存储引擎支持不同的锁机制.比如,MyISAM和MEMORY存储引擎采用的是表级锁(table-level loc ...
- spark[源码]-Pool分析
概述 这篇文章主要是分析一下Pool这个任务调度的队列.整体代码量也不是很大,正好可以详细的分析一下,前面在TaskSchedulerImpl提到大体的功能,这个点在丰富一下吧. DAGSchedul ...
- java虚拟机-垃圾回收算法
在Java中,程序员不需要去关心内存动态分配和垃圾回收的问题,这一切都交给了JVM来处理.但是首先需要明确,什么样的对象才能当为垃圾: 1.引用计数法:如果某个引用(即指针)指向对象,那么说明该对象还 ...
- Spring MVC 流程
1. 检查是否为上传文件. 2. 通过HandlerMapping获取HandlerExecutionChain: DispatcherServlet 中包含:handlerMappings , 遍历 ...
- QML学习之浅谈Window
转载地址:http://blog.csdn.net/kanchuan1905/article/details/53762788 在Qt Quick的世界里,Window对象用于创建一个与操作系统相关 ...
- NUMA架构的优缺点
numa把一台计算机分成多个节点(node),每个节点内部拥有多个CPU,节点内部使用共有的内存控制器,节点之间是通过互联模块进行连接和信息交互.因此节点的所有内存对于本节点所有的CPU都是等同的,对 ...
- 屏幕变黑白-winhotkey
下载了个windows hot key 的工具想看快捷键冲突 结果安装好之后屏幕变黑白了,变成辅助模式了.而且鼠标移动到哪都加蓝色框框 如果这个时候你带上耳机就能听到在朗读,这应该也是一种辅助模式 ...
- 在linux环境下安装python3.6
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz --no-check-certificat gunzip Python-3. ...
- Job流程:决定map个数的因素
此文紧接Job流程:提交MR-Job过程.上一篇分析可以看出,MR-Job提交过程的核心代码在于 JobSubmitter 类的 submitJobInternal()方法.本文就由此方法的这一句代码 ...