HandlerFactory.java :
/*
String[] config: { "/", "MainServlet", "/nav", "NavigationServlet" }
String requestUri: "/nav/test"
Correct result: "NavigationServlet"
*/
\\
public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
String res;
int max = 0, idMax = -1;
for (int i = 0; i<config.length; i+=2)
{
if(requestUri.startsWith(config[i]))
{
if(config[i].length() > max)
{
idMax = i+1;
max = config[i].length();
}
}
}
if (idMax != -1) res = config[idMax];
else res = "Yik8IM";
return(res);
}
}