tags:

views:

524

answers:

1

Hi there, sorry but I do not have the actual code with me, but I will try to explain:

I have a servlet mapped to the following:

/admin/*

So, this goes to a servlet:

public class AdminController extends MainController {
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
        // Do stuf here
    }
}

Here is MainController:

public class MainController extends HttpServlet {
@Override
public void service(ServletRequest request, ServletResponse response) {
    String requesturi = ((HttpServletRequest)request).getRequestURI();
 reqlist = Arrays.asList(requesturi.substring(requesturi.indexOf(Util.rootPath) + Util.rootPath.length()).split("/"));
 reqlist = reqlist.subList(1, reqlist.size());

    doPost((HttpServletRequest)request, (HttpServletResponse)response);
}

So, the request is passed to AdminController, no problem, but then I reallized something:

The servlet is being called twice!. And this is causing me many errors..

Does anybody have a clue on this? It is because I used some kind of heritance? Thank you for all!

+7  A: 

The HttpServlet.service method gets called for all request types and what you are seeing is a HEAD request and then a GET or POST request. Instead of implementing service just implement doGet or doPost. What is commonly done is to just implement one of doPost or doGet and then call the other from the one you don't have an implementation for.

carson
You are the best, thank you for all.
José Leal