Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Eclipse problem with servlet development

eclipse jsp java servlet servlet-mapping web.xml deployment descriptor

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1 Roman Y

Roman Y

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 196 posts

Posted 29 January 2013 - 08:55 AM

Hi, this is more of the environment + web development problem, but since there is no JSP/servlet sub-forum under the Web Development I'm throwing it here.

Anyway I am using the latest Eclipse (Juno) for Java EE developers. The problem is that I can't get the servlet mapping right and I don't really know whether it is my fault or something is wrong with the eclipse.

Anyway I've started with creating a Dynomic Web project and creating a Hello World servlet which automatically is placed in the /Java Resources/src/

package com.myservlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
* Servlet implementation class HelloWorld
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
	 * @see HttpServlet#HttpServlet()
public HelloWorld() {
	 // TODO Auto-generated constructor stub
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();

out.println("<title>Hello World!</title>");
out.println("<h1>Hello World!</h1>");


So everything is okay there. Then I wanted to configure the mapping so I am looked at Deployment Descriptor: HelloWorld/Servlet Mappings which told me that HelloWorld/webContent/WEB-INF-web.xml does not exists.

here is where it gets tricky: when I create a web.xml file at that location the Deployment Descriptor disappears. Well no biggie I go ahead and map everything manually: which at least according to me and some friends seems to be right. Here is what I am doing just in case:


<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">


So from here on I can't get it to map correctly. I've tried http://localhost:8080/HelloWorld, http://localhost:808...vlet/HelloWorld etc.. all of these return 404.

(I am using tomcat seven which is proven to be configured correctly because I got satisfying results when trying a simple HelloWorld with .jsp.

I have read that if I create a servlet with the wizard (I used the "create servlet" wizard the whole time) the Eclipse will automatically edit the web.xml for me so the servlet will get mapped right. The next part lets me to believe that something is wrong with the Eclipse since when I try to create a servlet after I've manually created a web.xml Eclipse has a strange way of denying me. When I fill in the package and the servlet name the next or finish buttons remain unclickable. When I check in the box that says "Choose an already existing servlet" or something similar it disables all the fields and when I uncheck the box all of the fields remain disabled (uneditable).

So I am kind of stuck and have next to none ideas of what to do next so any solutions/attempts/suggestions are appreciated. Thanks.

Created an identical project with an identical servlet, now without manually creating the web.xml I've right-clicked on the Deployment Descriptor and chose "Generate Deployment Descriptor Stub" not sure of what exactly it did, I am not sure, but I think it has generated some Welcome Pages. It seems to have also generated a web.xml within the WEB-INF (the required location), when I try to look at servlet mappings or the web.xml itself it still says "Resource '/HelloWorld/WebContent/WEB-INF/web.xml' does not exist".

Appearently the web.xml has been created (took itself some time to realize that), there was no servlets or servlet mappings in it. So I have generated another servlet (no change to web.xml) so I have manually added the servlet and the mapping. Still have 404 when going to http://localhost ...

After editing the web.xml manually the Deployment Descriptor disappeared.

I have realized that I might not have cleaned the Tomcat working directory properly and it might have been configured for an older project... so I am going to try cleaning it and re-build the project.

Cleaning directory and remaking the whole project did not affect anything, still having same problems.

Edited by Roman Y, 29 January 2013 - 10:13 AM.

#2 Roman Y

Roman Y

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 196 posts

Posted 29 January 2013 - 10:26 AM

Alright got it... The problem was that the mappings are no longer configured in the web.xml (if I understood correctly) instead you specify the mapping in the @WebServlet() at the servlet itself. So my @WebServlet("/HelloWorld") gave the mapping of the servlet to http://localhost:808...rld/helloworld. Changing it to @WebServlet("") or @WebServlet("/") gave me the correct mapping to localhost:8080/helloworld/

#3 Roman Y

Roman Y

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 196 posts

Posted 29 January 2013 - 01:32 PM

If I may continue with the topic, does anybody know why does Eclipse freak out when I try to edit web.xml? It seems reasonable that I should be able to do that if I'd like to configure something manually without Eclipse going haywire?

#4 speculatius


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 106 posts

Posted 29 January 2013 - 11:22 PM

Hmm. I dont use eclipse, but web.xml works fine for me in general. I found this topic which probably solves the issue with eclipse.

Edited by speculatius, 29 January 2013 - 11:22 PM.

#5 Roman Y

Roman Y

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 196 posts

Posted 30 January 2013 - 04:27 AM

My problem differs from the one described. It's not that the changes I make in the web.xml are not reflected the next time I deploy, it's that me editing web.xml in any way causes Eclipse to malfunction and do thing it is not supposed to.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download