Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet being called twice!

Tags:

java

servlets

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!

like image 765
José Leal Avatar asked Nov 29 '22 07:11

José Leal


1 Answers

Though it is old thread but my answer may help someone. Today I faced the same issue. My particular servlet is working fine earlier and suddenly it has started calling doGet method twice. On investigation, I found that my chrome browser has html validator extension which is calling the servlet again with same request to do html validation. After I disabling the extension, the problem got resolved.

like image 78
NIGAGA Avatar answered Dec 04 '22 11:12

NIGAGA