Master a simple Java programming challenge (STATUS: NOT PASSED)As the principal engineer of an HTTP web server, you are responsible for implementing the request processing subsystem of the server.
An incoming request for a specific resource, identified by an URI, must be dispatched to the appropriate handler according to the server configuration which maps URIs to request handlers. 'HandlerFactory.getHandler' must be implemented:public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
}
}The string array 'config' contains URI patterns and handler names. Two consecutive values form a key-value pair comprised of URI pattern and handler. 'requestUri' represents an incoming request, the URI to match against the configured handlers. 'getHandler' must return the correct handler for a given URI as a string value.An URI pattern never contains wildcards and represents the start of an URI string, a prefix. Matching must be implemented accordingly. The handler with the longest matching URI pattern wins if more than one pattern matches. If no handler can be found, "cJGHAec" must be returned. Example input: String[] config: { "/", "MainServlet", "/nav", "NavigationServlet" }
String requestUri: "/nav/test" Correct result: "NavigationServlet"In this example, the configuration contains a mapping of "/" to "MainServlet" and "/nav" to "NavigationServlet". In the case of an incoming URI "/nav/test.nav", "NavigationServlet" is the correct choice because its pattern is longer than that of "MainServlet".
public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
//To do
;
}
}
An incoming request for a specific resource, identified by an URI, must be dispatched to the appropriate handler according to the server configuration which maps URIs to request handlers. 'HandlerFactory.getHandler' must be implemented:public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
}
}The string array 'config' contains URI patterns and handler names. Two consecutive values form a key-value pair comprised of URI pattern and handler. 'requestUri' represents an incoming request, the URI to match against the configured handlers. 'getHandler' must return the correct handler for a given URI as a string value.An URI pattern never contains wildcards and represents the start of an URI string, a prefix. Matching must be implemented accordingly. The handler with the longest matching URI pattern wins if more than one pattern matches. If no handler can be found, "cJGHAec" must be returned. Example input: String[] config: { "/", "MainServlet", "/nav", "NavigationServlet" }
String requestUri: "/nav/test" Correct result: "NavigationServlet"In this example, the configuration contains a mapping of "/" to "MainServlet" and "/nav" to "NavigationServlet". In the case of an incoming URI "/nav/test.nav", "NavigationServlet" is the correct choice because its pattern is longer than that of "MainServlet".
public class HandlerFactory
{
public String getHandler(String[] config, String requestUri)
{
//To do
;
}
}
解决方案 »
- byte[ ]动态开辟小问题
- 求助:博客排名2万内,目前需要多少的访问量才可以做到? 100分送出
- 一个小问题,请教大家~~
- JAVA如何修改JDK功能?
- JTable的按列查询问题
- 请问 “public static 方法”的 public 有何意义 急。。有效回答马上给分
- 关于jsp中部署class文件
- 由于公司项目中遇到一个问题,怎么样在客户端用Java Applet截取所需要图片
- 问一个关于PACKAGE调用的问题,谢谢回答
- 海康SDK开发求解:海康预览时候可以设置OSD字符串,那么请问下预览时可以设置自定义的图标嘛?
- 一本不错的书《Java Swing(第二版)》
- 顷尽所有请教高手一个问题
String tmpstr = null;
String ru = requestUri;
int flag = 0;
int lastflag = 0;
int index = 0;
int i = 0;
for(i=0; i<config.length; i+=2){
flag = 0;
tmpstr = config[i];
for(int j=0; j<ru.length();j++){
if(tmpstr.length()>j){
if(tmpstr.substring(0,j+1).equalsIgnoreCase(ru.substring(0,j+1))){
flag++;
}
}
}
if(lastflag<flag){
lastflag = flag;
index = i;
}
}
if(lastflag==0)
return "cJGHAec";
return config[index+1];
}
你是不是就需要这样的效果啊?