1

The page can't be visited and showed following error message:

java.lang.NoSuchFieldError: ASYNC
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)

This is part of the error message in the page.

As my experience, this error is caused by the wrong reference using JSTL. Say I set a User in Controller. If I want to show the user name, I use <c:out value="${user.name}"/>. But if I use <c:out value="${user.namee}"/>, this error will occur.

So I wonder if I have lots of objects set in Controller, and have the message of these objects shown on page. How can I locate which one causes the error?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Sky
  • 7,343
  • 8
  • 31
  • 42

1 Answers1

1

In the standard Java EE API, ASYNC is recognizable as a field of DispatcherType enum.

This enum was introduced in Servlet 3.0. This problem thus suggests that webapp's runtime classpath is polluted with mixed Servlet API versions. E.g. Servlet 2.5 and Servlet 3.0 mixed. The implementation was loaded for Servlet 3.0 or newer (likely Jetty itself), but the API was loaded for Servlet 2.5 or older (likely via webapp).

The most common cause for this is that the WAR file mistakenly contains an Servlet API JAR file or even a Java EE JAR file in /WEB-INF/lib. You should make sure that the WAR's /WEB-INF/lib does not contain any libraries which are already provided by the target runtime itself (in your case, Jetty). This is regardless of the version used. Even if you align out the versions, you are just not supposed to provide server-specific libraries along with the webapp.

When you're using Maven, mark server-provided libraries as <scope>provided</scope> in webapp's pom.xml. When you're manually carrying around JARs, simply physically remove server-provided libraries from /WEB-INF/lib folder.

Do note that this has nothing to do with JSTL.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I checked my `pom.xml`, the `scope` for `servlet` is `provided`. I start the application with Jetty by running a class with Jetty API. The strange part is it works fine when I use `localhost` to visit my page. If I use the host name configured in `hosts`, such as `xz.xxx.com`, this error occurs. One thing needs to be noted that when using `xz.xxx.com`, it's passed to a filter then dispatch the url to the specific url I defined. Any ideas what's happening? – Sky Apr 20 '16 at 12:35
  • There exist dependencies which implicitly include Servlet 2.5, such as some Spring dependencies. You can verify it by letting Maven produce a WAR file and then inspecting its /WEB-INF/lib folder with a ZIP tool. – BalusC Apr 20 '16 at 12:40
  • My hosts file looks like this: `127.0.0.1 localhost 127.0.0.1 xz.jifang.cn 127.0.0.1 www.xz.jifang.cn 127.0.0.1 jifang.cn`, this error occurs when I use `http://xz.jifang.cn:8889/`, but it works fine with `http://jifang.cn:8889/` and `localhost:8889`. The only differences is when I use `http://xz.jifang.cn:8889`, the url will be caught by my filter and set some parameters to request, then use `request.getRequestDispatcher("common/index").forward(request, response);` to go to the home page. – Sky Apr 20 '16 at 14:54
  • This is not related to hosts. Filters just happen to use that enum. If you don't use a filter, then that enum class won't be loaded. Is that filter part of webapp itself or of 3rd party library? If part of your webapp, then you still have duplicate different versioned Servlet API libraries. If of 3rd party library, then apparently your Jetty server is not of a Servlet 3.0 compatible version (which should be really old as Servlet 3.0 was released 2009). – BalusC Apr 20 '16 at 15:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109699/discussion-between-sky-and-balusc). – Sky Apr 20 '16 at 15:07