jsp - struts2 使用 Spring Boot - JSP 未呈现
问题描述
亲爱的,我正在尝试使用 SpringBoot 迁移 Struts2 Web 应用程序。许多主题都在谈论未渲染和下载的 JSP,但我仍然找不到合适的解决方案。看起来好像没有调用 ACTION 类,但是找到并下载了 JSP,而不是渲染。
我已将我的 jsp 文件放入
src/main/resources/META-INF/资源
也试过
webapp 和 webapp/WEB-INF
我也尝试添加一个 Struts2Configuration 类:
@Configuration
public class Struts2Configuration {
@Bean
public ServletRegistrationBean servletRegistrationBean(final DispatcherServlet dispatcherServlet) {
final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet);
servletRegistrationBean.setEnabled(false);
return servletRegistrationBean;
}
@Bean
public FilterRegistrationBean someFilterRegistration() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new StrutsPrepareAndExecuteFilter());
registration.addUrlPatterns("*.action");
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD);
registration.setName("StrutsPrepareAndExecuteFilter");
return registration;
}
}
我的 pom.xml 的一部分:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<groupId>com.mycomp</groupId>
<artifactId>mycomp-project</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.1.3.Final</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB,
JiBX, Castor, XStream, and XML Beans. (depends on spring-core, spring-beans,
spring-context) Define this if you need OXM (org.springframework.oxm.*) -->
<!--<dependency>-->
<!--<groupId>org.springframework</groupId>-->
<!--<artifactId>spring-oxm</artifactId>-->
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>commons-lang</artifactId>-->
<!--<groupId>commons-lang</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.thoughtworks.xstream</groupId>-->
<!--<artifactId>xstream</artifactId>-->
<!--<version>1.4.9</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/ma.glasnost.orika/orika-core -->
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!--<dependency>-->
<!--<groupId>javax.servlet</groupId>-->
<!--<artifactId>javax.servlet-api</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>javax.servlet.jsp</groupId>-->
<!--<artifactId>javax.servlet.jsp-api</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-java8-support-plugin</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>repository.com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>oracle-jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<!--
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-bom</artifactId>
<version>${struts.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
-->
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
解决方案
你应该添加 application.properties
spring.mvc.view.prefix:/WEB-INF/views/
spring.mvc.view.suffix:.jsp
或 application.yml
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
推荐阅读
- c# - 如何解决此错误 stale element reference: element is not attach to the page document
- javascript - 如何删除 indicatorContainer(IndicatorsContainer 的第一个子项)的填充?
- google-bigquery - 将数据插入调整到 BigQuery
- python - 如何通过 pandas 读取 csv 作为其原始状态 [如不更改其格式]
- assembly - 将 x86 四元数组装到欧拉角输出错误的顺序
- html - 展开容器而不展开父/整行
- javascript - 在检查唯一值时使用 {} 或使用 new Set() 声明一个空对象更好吗?
- ios - 使用 react-native-community/voice 的语音到文本在 iOS 中没有给出正确的结果
- javascript - 尝试获取用户输入时未定义
- curl - 如何使用 ansible 模块将文件上传到 nexus?