简体   繁体   中英

Cannot select the project in the Create Servlet dialog in Eclipse

I'm experiencing an issue similar to this one but the solution provided doesn't cut it for me. So the issue in question is I can't select the project in the Create Servlet dialog in Eclipse . This prevents me from completing the process of creating a new servlet.

As recommended by the solution I have created a Dynamic Web Project and have ensured that the Dynamic Web Module is checked in foo -> Properties -> Project Facests . I'm also in the Java EE Perspective .

Project structure:-

文件夹结构

Create servlet wizard:- 新建 Servlet 向导

Project properties:- 项目属性

I'm running the following instance of Eclipse on Mac OS Mojave Version 10.14.5 :-

Eclipse IDE for Enterprise Java Developers.

Version: 2018-12 (4.10.0) Build id: 20181214-0600

Any help would be appreciated. Cheers!

Edit (.project file) below:-

   <?xml version="1.0" encoding="UTF-8"?>
      <projectDescription>
      <name>Foo</name>
      <comment></comment>
      <projects>
      </projects>
      <buildSpec>
         <buildCommand>
             <name>org.eclipse.jdt.core.javabuilder</name>
             <arguments>
             </arguments>
         </buildCommand>
         <buildCommand>

     <name>org.eclipse.wst.common.project.facet.core.builder</name>
        <arguments>
        </arguments>
    </buildCommand>
    <buildCommand>
        <name>org.eclipse.wst.validation.validationbuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>


<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>

 <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
     <nature>org.eclipse.jdt.core.javanature</nature>
 </natures>
</projectDescription>

This prevents me from completing the process of creating a new servlet.

Before a software is re-usable, it first has to be usable. I understand your frustrations with Eclipse. Try below steps:

  1. Restart Eclipse with -clean argument.
  2. If it still does not work, backup & delete the.metadata directory for the Eclipse workspace. .metadata is generally a hidden directory in the workspace directory. Repeat #1.
  3. Disable/Remove all third party plugins which are not part of the Eclipse default package and repeat #1.

By the way. There is always the old school way to create a Servlet . You can simply create a new Class and make it extend HttpServlet , and map it in web.xml .

Sample Servlet Java class

// Import other required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

// Extend HttpServlet class
public class HelloWorldServlet extends HttpServlet {

   private String message;

   public void init() throws ServletException {
      // Do required initialization
      message = "Hello World";
   }

   public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

      // Set response content type
      response.setContentType("text/html");

      // Actual logic goes here.
      PrintWriter out = response.getWriter();
      out.println("<h1>" + message + "</h1>");
   }

   public void destroy() {
      // do nothing.
   }
}

web.xml mapping

...
<servlet>
   <servlet-name>comingsoon</servlet-name>
   <servlet-class>mysite.server.ComingSoonServlet</servlet-class>
</servlet>
<servlet-mapping>
   <servlet-name>comingsoon</servlet-name>
   <url-pattern>/*</url-pattern>
</servlet-mapping>
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM