码迷,mamicode.com
首页 > 编程语言 > 详细

springboot跳转jsp页面

时间:2016-11-04 16:15:48      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:页面跳转   jsp标签   spring   snapshot   blog   odi   配置文件   ota   string   

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页面

标签:页面跳转   jsp标签   spring   snapshot   blog   odi   配置文件   ota   string   

原文地址:http://www.cnblogs.com/woms/p/6030476.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!