学jsp的应该学会做的一道题
来源:互联网 发布:牙齿抛光好不好知乎 编辑:程序博客网 时间:2024/05/17 06:51
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, "8EA5ve" 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".
我的解法
package java.test;
public class test
{
public static String getHandler(String[] config, String requestUri)
{
String str1="";
String str2="";
if(requestUri.indexOf(config[0])!=-1)
str1=config[0];
if(requestUri.indexOf(config[2])!=-1)
str2=config[2];
if(str1.length()>str2.length())
return config[1];
else if(str1.length()<str2.length())
return config[3];
else
return "7amgnh7";
}
public static void main(String [] args)
{
String[] config= { "/", "TestServlet", "/test", "TestServlet2" };
String requestUri="/";
System.out.println(getHandler( config, requestUri));
}
}
- 学jsp的应该学会做的一道题
- 设计师应该学会的行为设计学
- 做应该做的
- 学机械的同学丰大学应该做的几件事
- mooc中做的一道题
- 最近做的一道交互题
- 一道数学小题,做的很酸爽
- 学会假设人生其实是虚无无意义的情况下人应该做什么
- 大学应该做的...
- 男人学会做的事
- 学会做自己的朋友
- 学会做快乐的人
- 你应该会的一道多线程笔试题
- 男人应该学会的100句话【实用】
- 工作后应该学会的事情
- 大学毕业四年内应该学会的
- 女人应该学会优雅的转身
- 一个人在生活中应该学会的东西
- 请哪位高手讲解关于c中指针类型的转换
- sdsd
- 速度
- 设置VSS2005使支持通过Internet访问
- Lotus Notes and Domino入门讲座(三)-Domino组织和用户名
- 学jsp的应该学会做的一道题
- Javascript 二三事
- wsdfsljfslfsf
- 怎么判断链表中是否有环?
- 忍受AJAX
- 什么是 GRUB
- 简化版的LF线程池(领导者与跟随者模式)
- 采用C++的ACE库实现的一个通用的C/S架构通信程序(最终版)
- EntityManager:seam新手必读(一)