• SpringBoot_使用JSP


    在Spring boot中使用jsp,按如下步骤进行:

    1、在pom.xml文件中配置依赖项

    <!--引入Spring Boot内嵌的Tomcat对JSP的解析包-->
    <dependency>
       <groupId>org.apache.tomcat.embed</groupId>
       <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
    
    <!-- servlet依赖的jar包start -->
    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>
    </dependency>
    <!-- servlet依赖的jar包start -->
    
    <!-- jsp依赖jar包start -->
    <dependency>
       <groupId>javax.servlet.jsp</groupId>
       <artifactId>javax.servlet.jsp-api</artifactId>
       <version>2.3.1</version>
    </dependency>
    <!-- jsp依赖jar包end -->
    
    <!--jstl标签依赖的jar包start -->
    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>jstl</artifactId>
    </dependency>
    <!--jstl标签依赖的jar包end -->

    2、在application.properties文件配置spring mvc的视图展示为jsp:

    #springboot 集成jsp
    #如果jsp页面放在webapps根目录下面
    spring.mvc.view.prefix=/
    #如果jsp页面放在WEB-INF目录下面
    #spring.mvc.view.prefix=/WEB-INF/pages/
    spring.mvc.view.suffix=.jsp

    3、在src/main 下创建一个webapp目录,然后在该目录下新建index.jsp页面,pom.xml文件的build中要配置备注中的配置信息

    <resources>
       <resource>
          <directory>src/main/java</directory>
          <includes>
             <include>**/*.xml</include>
          </includes>
       </resource>
       <resource>
          <directory>src/main/resources</directory>
          <includes>
             <include>**/*.*</include>
          </includes>
       </resource>
       <resource>
          <directory>src/main/webapp</directory>
          <targetPath>META-INF/resources</targetPath>
          <includes>
             <include>**/*.*</include>
          </includes>
       </resource>
    </resources>

    控制器中的方法返回jsp页面

    @Controller
    public class HelloController {
        @Autowired
        private Myconfig myconfig;
    
        @RequestMapping("index.do")
        public Object list(Model model){
            model.addAttribute("userName","joinlabs");
            return "index";
        }
    }

    访问index.do就会跳转到index.jsp页面了,而且可以通过EL表达式获取到保存的参数的值

    学习中,博客都是自己学习用的笔记,持续更新改正。。。
  • 相关阅读:
    h5-canvas-渐变
    sublime text 3 无法安装Package Control插件解决办法
    ps;top;free;grep
    lambda
    服务注册与发现eureka
    https证书错误导致maven无法访问仓库出错
    Docker认识和安装
    spring项目发布到linux上遇到的错
    spring aop api
    spring事务
  • 原文地址:https://www.cnblogs.com/Tunan-Ki/p/11762336.html
Copyright © 2020-2023  润新知