本文介绍了将URL解析为组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Java中使用斜杠(例如 server / books / thrillers / johngrisham / thefirm
)解析描述性样式的URL。
I want to parse a descriptive-style URL with slashes (such as server/books/thrillers/johngrisham/thefirm
), in Java.
我的总体想法是处理我收到的数据,以便在数据库中进行查找(因此使用URL作为搜索条件),然后返回包含数据的HTML页面。
My overall idea is to handle the data I receive to do a lookup (therefore using the URL as search criteria) in a database and then return HTML pages with data on it.
我该怎么做?
推荐答案
String urlToParse = "server/books/thrillers/johngrisham/thefirm";
String[] parsedURL = urlToParse.split("/");
您将拥有的是一系列字符串,您可以使用它们。
What you will have is an array of strings that you can then work with.
// parsedURL[0] == "server";
// parsedURL[1] == "books";
// parsedURL[2] == "thrillers";
// parsedURL[3] == "johngrisham";
// parsedURL[4] == "thefirm";
这篇关于将URL解析为组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!