jsp - 使用 Spring Boot 的 struts2 - JSP 未呈现

标签 jsp spring-boot tomcat struts2

亲爱的, 我正在尝试使用 SpringBoot 迁移 Struts2 Web 应用程序。许多主题都在谈论 JSP,而不是呈现和下载,但我仍然找不到合适的解决方案。 看起来没有调用 ACTION 类,但是找到并下载了 JSP 而不是呈现。

我已经把我的jsp文件放在了

src/main/resources/META-INF/resources

也试过

webapp and 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

关于jsp - 使用 Spring Boot 的 struts2 - JSP 未呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074593/

相关文章:

java - Spring boot - 无法解析 jsp View

java - Action 类被调用两次

java - Spring Boot - 大量无效请求和套接字接受失败 java.io.IOException : Too many open files

java - 如何在 Spring Boot 应用程序中测试 Quartz 作业的正常工作

java - 在现有 Tomcat 中部署 Artifactory

eclipse - 404 错误 Apache Tomcat 7 从 Eclipse Juno IDE 运行 JSP 文件

jsp - 如何在JSTL中查找HashMap是否为空/空?

java - hibernate/JPQL : How to load parent with all childs based on query on a child

java - DHIS2 的替代用例

java - 为什么不调用 hibernate.cfg.xml 中的监听器?