开博之说

唉,刚才没保存,重新输入一遍。

给大家提供一个5M JSP空间的网站,免费并且支持java6.0有趣的是注册必须要先完成一道java测试题,他的在线编译和测试用例运行比较有意思

www.myjavaserver.com

 

Signup Challenge

<!--<h3>Option 2: Signup Challenge (instant access)</h3>--> 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, "mKgVEAQ" 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".

把代码贴到题目下面的文本编辑框里,后台会自动编译并测试,如果运行通过,则开放注册,否则给出错误提示

开博之说

java 代码
  1. public class HandlerFactory {   
  2.     public static final String NO_MAPPING = "GRcspP";   
  3.        
  4.     public String getHandler(String[] config, String requestUri) {   
  5.         String mappingServlet = NO_MAPPING;   
  6.         int preMappingLength = 0;   
  7.         for (int i = 0; i < config.length; i = i + 2) {   
  8.             String pattern = config[i];   
  9.             if (requestUri.startsWith(pattern) && pattern.length() > preMappingLength) {   
  10.                 mappingServlet = config[i + 1];   
  11.                 preMappingLength = pattern.length();   
  12.             }   
  13.         }   
  14.         return mappingServlet;   
  15.     }   
  16. }   

你可能感兴趣的:(jsp,Web,Access)