I have been following the netbeans ecommerce tutorial and they introduced a ControllerServlet which they setup to deal with multiple URLs.
However the way they do this is basically to have a big if then else if
statement:
String userPath = request.getServletPath();
// if category page is requested
if (userPath.equals("/category")) {
// TODO: Implement category request
// if cart page is requested
} else if (userPath.equals("/viewCart")) {
// TODO: Implement cart page request
userPath = "/cart";
// if checkout page is requested
} else if (userPath.equals("/checkout")) {
// TODO: Implement checkout page request
// if user switches language
} else if (userPath.equals("/chooseLanguage")) {
// TODO: Implement language request
}
Is this really the recommended way of handling multiple URLs in a single servlet? This approach seems horrible and difficult to manage.
Or am I missing some obvious way of handling this cleanly?