java.lang.NoSuchFieldError:NON_BRIDGED_METHODS

时间:2014-03-06 10:42:32

标签: java spring jsp

我正在使用Spring MVC,我编写了一个普通的登录应用程序,但不断收到此错误。感谢任何帮助。

的index.jsp

<html>
<head>
<title>Home</title>
</head>
<body>
  <h1>Hello World!</h1> 
<hr/> 
    <form action="hello.html" method="post">  
    Name:<input type="text" name="username"/><br/>  
    Password:<input type="password" name="password"/><br/>  
    <input type="submit" value="login"/>  
    </form>  

</body>
</html>

HelloWorldController.java

@Controller
@RequestMapping(value = "/hello.html")
public class HelloWorldController {

    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView helloWorld(HttpServletRequest request,
            HttpServletResponse res) {
        String name = request.getParameter("username");
        String password = request.getParameter("password");

        if (password.equals("admin")) {
            String message = "HELLO " + name;
            return new ModelAndView("hellopage", "message", message);
        } else {
            return new ModelAndView("errorpage", "message",
                    "Sorry, username or password error");
        }
    }

}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>NewProject</display-name>

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
                       org.springframework.web.servlet.DispatcherServlet
                </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
                      org.springframework.web.context.ContextLoaderListener
                </listener-class>
    </listener>

</web-app>

调度-servlet.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:component-scan base-package="com.abc" />

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean>

</beans>

控制台:

java.lang.NoSuchFieldError: NON_BRIDGED_METHODS
    at org.springframework.web.bind.annotation.support.HandlerMethodResolver.init(HandlerMethodResolver.java:90)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.<init>(AnnotationMethodHandlerAdapter.java:399)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.<init>(AnnotationMethodHandlerAdapter.java:398)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.getMethodResolver(AnnotationMethodHandlerAdapter.java:389)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.supports(AnnotationMethodHandlerAdapter.java:315)
    at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:976)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:762)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:709)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:613)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:536)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

hellopage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Home</title>
</head>
<body>
  <h1>Hello World!</h1> 
<hr/> 
  Message is: ${message}  

</body>
</html>

2 个答案:

答案 0 :(得分:0)

我注意到提供的代码存在两个问题。

首先,表单提交到hello.html,但@RequestMapping映射到/hello。要解决此问题,请调整@RequestMapping

@RequestMapping(value = "/hello.html")
public class HelloWorldController 

使用@RequestMapping时,必须将以下行添加到dispatcher-servlet.xml文件中以启用Spring @RequestMapping等注释:

<mvc:annotation-driven/>

答案 1 :(得分:0)

今天遇到同样的问题。我发现我的项目有多个版本的相同Spring组件。