public String getHandler(String[] config, String requestUri)
    {
        int length = config.length;
        boolean flag = false;
        String result = null;        
        //sort String[]
        String tmpKey = null;
        String tmpValue = null;
        
        for(int j = 0; j < length - 1; j += 2)
        {
            for(int k = j; k < length - 3; k += 2 )
            {
                if(config[k].length() > config[k + 2].length())
                {
                    tmpKey = config[k];
                    tmpValue = config[k + 1];
                    
                    config[k] = config[k + 2];
                    config[k + 1] = config[k + 3];
                    
                    config[k + 2] = tmpKey;
                    config[k + 3] = tmpValue;
                }
            }
        }
        
        for(String tmp : config)
            System.out.println(tmp);
        
        for (int i = length - 1; i >= 0; i -= 2)
        {
            if (requestUri.contains(config[i - 1]))
            {
                result = config[i];
                flag = true;
                break;
            }
        }        if (flag)
            return result;
        else
            return "IVbnrNB";
    }
通过测试恶心的测试 竟然不让用Arrays.sort
就随便写了个冒泡

解决方案 »

  1.   

    Testcase 5 failed:
      config: { "/test", "TestServlet", "/test2", "TestServlet2" }
      request: "/servlet/TestServlet"
    ERROR: A testcase failed, please revise your codeTestCase 5没有通过啊,老兄
      

  2.   

    return "IVbnrNB";  
    IVbnrNB 是随机产生的 这个可能要修改
      

  3.   

    怎么改啊,我也想搞了jsp空间
      

  4.   

    Signup
    MyJavaServer provides a development environment for Java web applications.An open environment like MJS is a target of malicious users who abuse our services for illegal or simply inappropriate activities.
    In order to minimize abuse and yet provide our services to all interested Java developers for free, we require you to demonstrate your Java skills. The challenge is easy to master but does require some knowledge of the Java programming language.Signup Challenge
    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, "ufNDEo" 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".
    我的题目如上,谢谢!
      

  5.   

    If no handler can be found, "ufNDEo" must be returned.