首页 > 代码库 > springboot跳转jsp页面
springboot跳转jsp页面
springboot支持jsp页面跳转
官方不推荐jsp的支持,个人认为jsp在web层,用tomcat支持比较好
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跳转jsp页面
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。