简体   繁体   中英

URL behavior to access server side resource in Java/J2EE

My deployment descriptor is as follows

<servlet>
    <servlet-name>postServlet</servlet-name>
    <servlet-class>com.http.post.PostServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>postServlet</servlet-name>
    <url-pattern>/postServlet</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>postServlet</servlet-name>
    <servlet-class>com.http.post.PostServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>postServlet</servlet-name>
    <url-pattern/>
</servlet-mapping>

I'm Able to access PostServlet by hitting following URLs

Pls assume /url/to/my/server as

http://myserver:8080

/url/to/my/server/MyWebAppName
/url/to/my/server/MyWebAppName  (few white spaces at the end of context)
/url/to/my/server/HTTPMethods/
/url/to/my/server/HTTPMethods/////
/url/to/my/server/HTTPMethods///postServlet
/url/to/my/server/HTTPMethods///postServlet   (few white spaces here too)

Can some one pls explain this behavior by generalizing things?

How ever, if any space is present in between, it failes /url/to/my/server/HTTPMethods/// // This makes sense, because browser encodes spaces with %20

Is there any specific reason why trailing spaces are ignored

And failure in case of below URL /url/to/my/server/HTTPMethods/////postServlet//

It might be quite confusing to read, but all your questions can be answered by the URL spec

Basically, leading and trailing whitespaces are simply stripped off (if you really need white spaces as part of the URL you should encode them as %20

Regarding the notation HTTPMethods///postServlet, multiple slashes are simply treated as a single one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM