Reputation: 31
Am using eclipse JUNO to run a simple "Helloworld" servlet and am using JBoss 7.1 as server..
Here is the code am running with
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;
public class Hello extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
and my web.xml is(even after running the servlet)
<display-name>bjp</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>
</web-app>
means looking at this, it is clear that web.xml is not getting updated with the servlet information, like servlet mapping and servlet class..
Why web.xml is not getting updated with servlet class?? It works fine with Tomact..Please Help me
Upvotes: 2
Views: 4419
Reputation: 6181
Which version of the servlets you are using? if you are using Servlets3.0 then the servlets can be configured by @WebServlet
annotation, so there is no need for web.xml
configuration, that is the reason why Eclipse doesn't update web.xml
file automatically when you create servlet
. So you can have a code like this:
@WebServlet("/Hello")
public class Hello extends HttpServlet {
It will be do the same work as web.xml
configuration will do.
If you still want to generate web.xml
and dont want to use annotations then you have to change version
while creating the dynamic web project from 3.0
to 2.5
.
Upvotes: 3