zoukankan      html  css  js  c++  java
  • 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表达式获取到保存的参数的值

    学习中,博客都是自己学习用的笔记,持续更新改正。。。
  • 相关阅读:
    微信第三方平台开发之代小程序实现业务
    解决Chrome网页编码显示乱码的问题
    .Net Core 使用 System.Drawing.Common 在CentOS下报错
    CentOS安装nmap端口查看工具
    解决Nginx反向代理不会自动对特殊字符进行编码的问题 如gitblit中的~波浪线
    Centos7最小安装化后安装图形界面
    手把手教您在 Windows Server 2019 上使用 Docker
    windows10下安装docker报错:error during connect
    git删除远程分支
    linux下shell显示git当前分支
  • 原文地址:https://www.cnblogs.com/Tunan-Ki/p/11762336.html
Copyright © 2011-2022 走看看