JSP programming, the difference between a slash and no slash in a URL

Source: Internet
Author: User

JSP programming, the difference between slash and no slash in URLs (sendredirect,requestdispatcher,servlet,filter)

Transferred from: http://blog.csdn.net/tanyit/article/details/7319372

The difference between a slash "/" in a URL and no slash:

Set WebApp as the Web package name

In general, the non-slash form (such as "example.jsp") requests a resource http://localhost:8080/webapp/examole relative to the current page path;

The form of a slash ("/example.jsp") requests a resource under the root of the server, and the full URL is composed of the server address +/example: http://localhost:8080/example. If the page is not placed in the server and directory but under the Web package, you cannot use the backslash form.


This program is under Webroot file member file: Plus/Slash <jsp:include page= "/navservlet?method=navlist" ></jsp:include>

This app is under Webroot: no slashes <jsp:include page= "Navservlet?method=navlist" ></jsp:include>



Different URLs in the Sendredirect and Getrequestdispatcher methods:


Response.sendredirect (URL): url= "Example", address relative to the current requested directory; Url= "/example", the requested address is example under the server root directory, such as "Http://localhost:8080/example". Therefore, URLs in the Sendredirect method are usually not preceded by "/". The URL of the sendredirect is differentiated in a manner consistent with the usual situation.

Request.getrequestdispatcher (URL) is different from Sendredirect: Url= "example" points to a resource relative to the current request address, and "/" begins with the resource under the Web program root directory/webapp/ Example

Servlet-mapping's url:servlet URLs usually need to be preceded by a slash. For example, the action of a form Url= "a" (because the/a points to the server root directory), the corresponding servlet-mapping URL is/A.

How to match the URL of servlet-mapping:


/ex/*: Start with a slash, suffix wildcard characters,/ex,/ex/a can match;

*.do: Wildcard * post-dot, suffix do end, indicating that URLs with a. Do end match. such as Renren's home.do is one example, struts in a large number of use. Do and. Action suffixes. This suffix can be arbitrarily set by the developer, because it does not point to the actual file, which is used to match the servlet or filter.

/ex/: is an exact match, only the URL is/ex/when matching,/ex,/ex/a are not.

Filter-mapping and servlet-mapping are the same.


JSP programming, the difference between a slash and no slash in a URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.