Proper way to check for URL equality

后端 未结 3 1468
無奈伤痛
無奈伤痛 2021-02-02 11:53

I have the following scenario:

URL u1 = new URL(\"http://www.yahoo.com/\");
URL u2 = new URL(\"http://www.yahoo.com\");

if (u1.equals(u2)) {
    System.out.prin         


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-02 12:40

    Strictly speaking they are not equal. The optional trailing slash (/) is only a common usage but not a must. You could display different pages for

    http://www.yahoo.com/foo/
    

    and for

    http://www.yahoo.com/foo
    

    It's even possible for the one you provided I believe the HTTP header could skip that slash.

提交回复
热议问题