0

Servlet not working in newly created Dynamic Web Project in Eclipse Juno for Java EE. Here is how it goes, from scratch:

  • I downloaded Eclipse EE (Juno), didn't change any of default config
  • I downloaded latest Tomcat (7.0.30)
  • In Preferences > Server > Runtime Environments I added new Apache Tomcat v7.0
  • I created new Dynamic Web Project called UniBudget (context root: budget)
  • I added new file (index.jps with "it works!" inside)

At this moment after adding project to server and running it I could see "it works!" on screen. So, deployment works.

  • Next I added servlet file (control.Controller.java):

    package control;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    @WebServlet({ "/Controller", "*.do" })
    public class Controller extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        public Controller() {
            super();
        }
    
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            System.out.println("doGet()");
        }
    
        protected void doPost(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            System.out.println("doPost()");
        }
    
    }
    
  • I changed index.jsp to look like this, nothing more:

    <jsp:forward page="/departments.do"/>
    
  • And of course web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
        <display-name>UniBudget</display-name>
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
            <welcome-file>index.htm</welcome-file>
            <welcome-file>index.jsp</welcome-file>
                <welcome-file>default.html</welcome-file>
                <welcome-file>default.htm</welcome-file>
            <welcome-file>default.jsp</welcome-file>
        </welcome-file-list>
    
        <!-- servlet definition -->
        <servlet>
            <servlet-name>Do</servlet-name>
            <servlet-class>control.Controller</servlet-class>
        </servlet>
        <!-- servlet mapping -->
        <servlet-mapping>
            <servlet-name>Do</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>Do</servlet-name>
            <url-pattern>/Controller</url-pattern>
        </servlet-mapping>
    </web-app>
    
  • Generated .class files have to be in WEB-INF/classes right? That's what I read. So: Configure Build Path > Source tab > Browse > I created classes folder in WEB-INF (in Advanced I linked to folder in file system: ... /UniBudget/build/classes)

  • This is the file hierarchy in project:

file hierarchy in project

  • I cleaned and built the UniBudget project and republished to server. Cleaned the server.

  • I thought I would work now (I mean displaying "doGet()" or "doPost()" in Console). But instead of printout in Console I got this error:

    HTTP Status 404 - /budget/departments.do
    
    --------------------------------------------------------------------------------
    
    type: Status report
    
    message: /budget/departments.do
    
    description: The requested resource is not available.
    
  • the same happens when I try to directly access http://localhost:8080/budget/Controller (without redirection from index.jsp)

It looks like Eclipse could not see the servlet at all! Could you please point me where I make the mistake? I can't figure this out for hoours now.


EDIT:

After removing redundant annotation (@WebServlet), another error occurs:

HTTP Status 503 - Servlet Do is currently unavailable

--------------------------------------------------------------------------------

type Status report

message Servlet Do is currently unavailable

description The requested service is not currently available.

Error in console:

wrz 24, 2012 9:34:15 PM org.apache.catalina.core.ApplicationDispatcher invoke
WARNING: Servlet Do is currently unavailable

Not much. But that's all.


EDIT:

I found yet another error taking place here. I'm not even sure how to recreate it, but at least this one provides some more log info:

HTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 3

--------------------------------------------------------------------------------

type: Exception report

message: An exception occurred processing JSP page /index.jsp at line 3

description: The server encountered an internal error that prevented it from fulfilling this request.

exception: 

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 3

1: <%@ page language="java" contentType="text/html; charset=UTF-8"
2:     pageEncoding="UTF-8"%>
3: <jsp:forward page="/departments.do"/>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause: 

javax.servlet.ServletException: Error instantiating servlet class control.Controller
    org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
    org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


root cause: 

java.lang.ClassNotFoundException: control.Controller
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
    org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:65)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

EDIT:

Error during project right click > Export > WAR file:

java.lang.NoClassDefFoundError: org/eclipse/wst/web/internal/deployables/IFlatDeployable
    at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.getModuleParticipants(JavaEEComponentExportOperation.java:77)
    at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.getParticipants(JavaEEComponentExportOperation.java:43)
    at org.eclipse.jst.j2ee.internal.archive.operations.JavaEEComponentExportOperation.createFlatComponentArchiver(JavaEEComponentExportOperation.java:91)
    at org.eclipse.jst.j2ee.internal.archive.operations.ComponentExportOperation.export(ComponentExportOperation.java:191)
    at org.eclipse.jst.j2ee.internal.archive.operations.ComponentExportOperation.execute(ComponentExportOperation.java:136)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl$1.run(DataModelPausibleOperationImpl.java:385)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:410)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(DataModelPausibleOperationImpl.java:360)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.doExecute(DataModelPausibleOperationImpl.java:247)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.executeImpl(DataModelPausibleOperationImpl.java:219)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.cacheThreadAndContinue(DataModelPausibleOperationImpl.java:89)
    at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.execute(DataModelPausibleOperationImpl.java:207)
    at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard$1CatchThrowableRunnableWithProgress.run(DataModelWizard.java:220)
    at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
18
  • set classpath in system environment variable Sep 24, 2012 at 13:37
  • Could you elaborate? I'm not sure if I know how to do this.
    – alex
    Sep 24, 2012 at 13:44
  • 3
    So: Configure Build Path > Source tab > Browse > I created classes folder in WEB-INF (in Advanced I linked to folder in file system: ... /UniBudget/build/classes) You should not have performed this step! Eclipse will do it automagically while building a "Dynamic Web Project".
    – BalusC
    Sep 24, 2012 at 13:46
  • @BalusC I reverted the default output folder to UniBudget/build, but it changed nothing (and WEB-INF/classes is not being automatically (nor even automagically!) created by Eclipse).
    – alex
    Sep 24, 2012 at 13:51
  • 1
    The web.xml is redundant as well: you're using annotations. Why define the same thing twice?
    – JB Nizet
    Sep 24, 2012 at 14:22

2 Answers 2

3
java.lang.NoClassDefFoundError: org/eclipse/wst/web/internal/deployables/IFlatDeployable

Whoops. That's a pretty serious error, this class is namely internal to Eclipse. This has been reported once as Eclipse issue 388698, but this was unfortunately closed off as WORKSFORME. This seems to be an environment/platform/configuration specific problem after all. I'd consider re-posting the same issue along with as much as possible detail about the environment used (OS make/version, JRE/JDK make/version, hardware specs, etc).

I have personally not tried Juno yet (I usually wait for a SR1 to be released around winter so that all major teething issues are covered), but if completely deleting the Eclipse installation and re-unzipping it doesn't work, then I'd suggest to try to step back to the previous Eclipse version, which is Indigo SR2. Make sure that you download the right version for your platform (32bit vs 64bit).

0
0

For me the

java.lang.NoClassDefFoundError: org/eclipse/wst/web/internal/deployables/IFlatDeployable

error was caused by the following plugin:

WTP Patches for org.eclipse.jst.web_core.feature 3.4.0.v201207092049-20F8O7w312318212711

After the plugin was disabled I was able to package a war using Eclipse and deploy it.

(This solution comes from the URL Bug 388698 - Error exporting WAR file mentionned by BalusC)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.