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:-
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:
-clean
argument. 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.