Вам необходимо установить параметр redirect_uri в качестве URL-адреса сервлета.
@WebServlet("your/servlet/Url")
public class MyServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
public MyServlet()
{
super();
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//get the authorization code
String code = request.getParameter("code");
//get tokens and use them as per your requirement using code
...
//redirect user to the final destination
response.sendRedirect("url");
}
}