2016年8月18日 星期四

JSTL

JSTL Core <c:param> Tag

The <c:param> tag allows proper URL request parameter to be specified with URL and it does any necessary URL encoding required.

Example:

If you need to pass parameters to a tag, use the tag to create the URL first as shown below:
<c:url value="/index.jsp" var="myURL">
   <c:param name="trackingId" value="1234"/>
   <c:param name="reportType" value="summary"/>
</c:url>
<c:import url="${myURL}"/>
Above request would pass URL as below
"/index.jsp?trackingId=1234;reportType=summary"


JSTL Core <c:url> Tag

The <c:url> tag formats a URL into a string and stores it into a variable. This tag automatically performs URL rewriting when necessary. The var attribute specifies the variable that will contain the formatted URL.
The JSTL url tag is just an alternative method of writing the call to the response.encodeURL() method. The only real advantage the url tag provides is proper URL encoding, including any parameters specified by children param tag.

Example:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:url> Tag Example</title>
</head>
<body>
<a href="<c:url value="/jsp/index.htm"/>">TEST</a>
</body>
</html>
This would produce following result:
TEST


0 意見:

張貼留言