Você Esta usando alguma framework (Struts por exemplo) ?
Se estiver usando Servlet direto pode fazer o seguinte:
public class ControllServlet extends HttpServlet {
private static final long serialVersionUID = -8791581674710726725L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doExecute(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doExecute(request, response);
}
private void doExecute(HttpServletRequest request, HttpServletResponse response) throws ServletException {
String acao = request.getParameter("acao");
Method method;
try {
//Acha o methodo passado pelo paramentro acao
method = this.getClass().getMethod(acao, new Class<?>[] {HttpServletRequest.class, HttpServletResponse.class});
//Invoca este metodo
method.invoke(this, new Object[] {request, response});
} catch (SecurityException e) {
throw new ServletException(e);
} catch (NoSuchMethodException e) {
throw new ServletException(e);
} catch (IllegalArgumentException e) {
throw new ServletException(e);
} catch (IllegalAccessException e) {
throw new ServletException(e);
} catch (InvocationTargetException e) {
throw new ServletException(e);
}
}
//Um exemplo de acao
public void acao1(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
//Outro exemplo de acao
public void acao2(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
}
Mapeando este servlet para “servlet/ControllServlet”, a seguinte URL acionara o método “public void acao1(HttpServletRequest request, HttpServletResponse response)”
http://localhost:8080/Teste/servlet/ControllServlet?acao=acao1
Já a URL http://localhost:8080/Teste/servlet/ControllServlet?acao=acao2, executara o metodo “public void acao2(HttpServletRequest request, HttpServletResponse response)”
Isto esta bem tosco, vc tem que tratar os erros, um método default, etc etc etc.
Eu recomento que você procure usar uma framework para isso (Struts, VRaptor, Webwork, …) Veja mais algumas em http://www.java-source.net/open-source/web-frameworks