HTTP状态500 - 处理程序处理失败;嵌套异常是java.lang.NoSuchMethodError:

时间:2017-06-27 19:12:22

标签: spring spring-mvc

我的应用程序有jsp和html页面

@Controller
public class LoginController {
    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
    public String welcome() {
        System.out.println("==============21=========");
        return "welcome";
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String redirect() {
        System.out.println("==========1======");
        return "redirect:/LoginPage.html";
    }
}

当页面返回HTML页面时,我正在

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;

但是当它重定向到/ welcome时不会发生这样的错误

完成日志

 type Exception report

消息处理程序处理失败;嵌套异常是java.lang.NoSuchMethodError:javax.servlet.http.HttpServletResponse.getHeader(Ljava / lang / String;)Ljava / lang / String;

说明服务器遇到内部错误,导致无法完成此请求。

例外

org.springframework.web.util.NestedServletException:处理程序处理失败;嵌套异常是java.lang.NoSuchMethodError:javax.servlet.http.HttpServletResponse.getHeader(Ljava / lang / String;)Ljava / lang / String;     org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1303)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)     org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)     javax.servlet.http.HttpServlet.service(HttpServlet.java:617)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)     javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 根本原因

java.lang.NoSuchMethodError:javax.servlet.http.HttpServletResponse.getHeader(Ljava / lang / String;)Ljava / lang / String;     org.springframework.web.context.request.ServletWebRequest.checkNotModified(ServletWebRequest.java:187)     org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:240)     org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)     org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)     javax.servlet.http.HttpServlet.service(HttpServlet.java:617)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)     javax.servlet.http.HttpServlet.service(HttpServlet.java:723) note备注根本原因的完整堆栈跟踪可在Apache Tomcat /6.0.48日志。

中找到

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.test</groupId>

    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <url>http://maven.apache.org</url>
    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.4.1</version>
        </dependency>
        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Apache Commons DBCP -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- Spring ORM -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/jstl/jstl -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
    <build>


        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>

    </build>
    <properties>
        <spring.version>4.2.1.RELEASE</spring.version>
        <security.version>4.0.3.RELEASE</security.version>
        <jdk.version>1.8</jdk.version>
        <hibernate.version>4.3.5.Final</hibernate.version>
        <org.aspectj-version>1.7.4</org.aspectj-version>
    </properties>
</project>

请告诉我失败的地方。

1 个答案:

答案 0 :(得分:1)

HttpServletResponse.getHeader是servlet 3.0规范中的一个方法。我猜你的运行时环境不兼容。尝试将此添加到您的pom。

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

如果这不起作用,请尝试调整您使用IDE设置的运行时。您明确告诉它在任何特定服务器上运行吗?确保它与servlet 3.0兼容。因此,如果以Tomcat为例,请确保它至少是Tomcat 7。