温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Spring打包jar包时jsp页面无法访问怎么办

发布时间:2020-07-27 10:23:00 来源:亿速云 阅读:473 作者:小猪 栏目:编程语言

这篇文章主要讲解了Spring打包jar包时jsp页面无法访问怎么办,内容清晰明了,对此有兴趣的小伙伴可以学习一下,相信大家阅读完之后会有帮助。

spring打包jar包时jsp页面无法访问

问题如下

Spring打包jar包时jsp页面无法访问怎么办

当前pom.xml配置

<build>
    <resources>
      <!--引入配置文件-->
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <!--引入静态文件-->
      <resource>
        <directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        
      </plugin>
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
          <skipTests>true</skipTests> 
        </configuration> 
      </plugin>
    </plugins>
  </build>

解决办法:

1.高版本的插件不支持jsp,给spring-boot-maven-plugin指定版本号“1.4.2.RELEASE”

<build>
    <resources>
      <!--引入配置文件-->
      <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
      </resource>
      <!--引入静态文件-->
      <resource>
        <directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.4.2.RELEASE</version>
      </plugin>
      <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-surefire-plugin</artifactId> 
        <configuration> 
          <skipTests>true</skipTests> 
        </configuration> 
      </plugin>
    </plugins>
  </build>

2.根据spring官网说明,可打包war包,仍然可使用jar -jar xxx.war执行。

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-jsp-limitations

JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.

With Jetty and Tomcat, it should work if you use war packaging. An executable war will work when launched with java -jar, and will also be deployable to any standard container. JSPs are not supported when using an executable jar.

Undertow does not support JSPs.

Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.

<packaging>war</packaging>

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-documentation

spring官方不推荐使用jsp,推荐使用thymeleaf、freemaker、velocity等其他模块引擎。

看完上述内容,是不是对Spring打包jar包时jsp页面无法访问怎么办有进一步的了解,如果还想学习更多内容,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI