C:url Label

Source: Internet
Author: User

<c:url> tags

The main function of the <c:url> tag is to reconstruct the URL according to a specific rewrite rule, which has the following basic syntax:

<c:url value= "Original URL" var= "the name variable that holds the new URL" scope= "{page|request|session|application}"/>

The <c:url> tag stores the regenerated URL in the named variable specified by the var attribute, and the scope property specifies the range of the named variable, and its default value is page range.

For example, the following <c:url> tag creates a myurl named variable within the page range, with a value of "dir2/target.jsp":

<c:url value= "dir2/target.jsp" var= "Myurl"/>

For example, the Value property in the following <c:url> tag starts with "/" and the,<c:url> tag adds the root path of the current web app to the regenerated URL, so the myurl named variable has the values "/helloapp/dir1/dir2/ Target.jsp ":

<c:url value= "/dir1/dir2/target.jsp" var= "Myurl"/> <a href= "${myurl}" >target.jsp </a>

You can include the <c:param> Sub-tab in the <c:url> tab to set the request parameters, for example, the following <c:url> tag contains two <c:param> sub-tags, They are used to set username request parameters and description request parameters, respectively:

<c:url value= "/dir1/dir2/target.jsp" var= "Myurl" > <c:param name= "username" value= "Tom"/> <c:param nam E= "description" value= "age>10&age<30"/> </c:url> <a href= "${myurl}" >target.jsp </a>

The <c:param> tag correctly encodes special symbols in the Value property, such as > and &. The code generated by the <a> tag above is:

<a href= "/helloapp/dir1/dir2/target.jsp?username=tom&description= age%3e10%26age%3c30" > target.jsp </ A>

As can be seen from the above code, the ">" symbol in the description parameter value is encoded as "%3e", the "&" symbol is encoded as "%26", and the "<" symbol is encoded as "%3c".

The Name property of the <c:param> tag sets the request parameter name, the Value property sets the request parameter value, and in addition, the request parameter value can be set within the tag body. For example, the following <c:param> tag body determines if the username named variable is "Tom", and if the condition is met, the role request parameter is set to "Manager", if the username named variable is empty or not "Tom", Set the role request parameter to "Employee":

<c:url value= "/dir1/dir2/target.jsp" var= "Myurl" > <c:param name= "Role" > <c:if test= "${username== ' Tom      '} ' > Manager </c:if> <c:if test= "${empty username | |! username== ' Tom '}" > Employee </c:if> </c:param> </c:url> <a href= "${myurl}" >target.jsp </a>

If the username named variable is empty, then the code generated by the <a> tag is:

<a href= "/helloapp/dir1/dir2/target.jsp?role=employee" >target.jsp </a>

Source: 8500708

C:url Label

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.