Consider the URL below as an example.
Is there any way by which I can get "example.com" as an output. I know that a method is to appreciate any help. In , you can obtain different parts of the URI by using the methods below. You can also use them for rebuilding the URL fragment (debugging, or other tasks): So closest we need you For "root domain", you get back from For the pattern you provided (one-third + second level + C ohm / net), you should get the following: The following input / output will be given: servletrequest.getServerName () . This gives me test1.example.com
// Example: http: // myhost: 8080 / people ? Lastname = Fox and age = 30 string uri = request.getScheme () + ": //" + // "http" + ": // request.getServerName () + //" myhost "": "+ request.getServerPort () "//": "+" 8080 "request.getRequestURI () + //" / people "(request.getQueryString ()! = Tap?"? "+ Request.getQueryString ():" "); // "?" + "Lastname = fox and age = 30"
"root domain":
string with
getServerName () Have to work. This is necessary because the Servlet will not have any method to call "Host" before calling or from the time that
.com (this is called a
com in your network The machine can be - and not just a suffix - who knows?).
string domain = request .getServerName (). ReplaceAll (". * \\. (? =. * \\.)", "");
www.test.com -> Test.com test1.example.com - & gt; Example.com a.b.c.d.e.f.g.com - & gt; G.com www.com - & gt; Www.com.com - & gt; Com
No comments:
Post a Comment