/java/

jsp, el, jstl

2013-01-06 20:47:08

JSP - JavaService Pages

<%= "Hello World!"; %>
<%= metoda() %> the same as this <%= out.println( metoda() ); %>
<%= reguest.getAttribute("someName"); %>
<%= ((Pracownik)session.getAttribute("zalogowny")).getPesel() %>

<jsp:include page='"menu.jsp"'>
<jsp:param name='"param1"' value='"menu1"'></jsp:param>
<jsp:param name='"param2"' value='"menu2"'></jsp:param>
</jsp:include>

EL - Expression Language

${reguestScope.someName}
${sessionScope.zalogowny.pessel}

JSTL - JavaServer Pages Standard Tag Library

Core

(echo)


<c:out value='"${user.name}"'>No data</c:out>

(if)


<c:if !='null}"' test='"${sessionScope.zalogowny'>
    Some message
</c:if>

(switch)


<c:choose>
<c:when =='null}"' test='"${sessionScope.data'>
        Data is not egzist
    </c:when>
<c:when sessionscope.data}&quot;="" test='"${empty'>
        Data is empty
    </c:when>
<c:when sessionscope.data}&quot;="" test='"${!empty'>
        Data is not empty
    </c:when>
</c:choose>

(switch default / if else)


<c:choose>
<c:when (empty="" sessionscope.user.name)}&quot;="" test='"${not'>
        User name is ${sessionScope.user.name}
    </c:when></c:choose>

<c:otherwise>
        User is empty
    </c:otherwise>

(foreach)


<c:foreach items='"${sessionScope.products}"' var='"p"'>
    ${p.name}
    ${p.desc}
</c:foreach>

(try catch)


<c:catch var='"exception"'>
    ${3/"string"}
</c:catch>

<c:if (empty="" exception)}&quot;="" test='"${not'>
    Exception: ${exception}
</c:if>

(url encoder)


<c:url value='"/page/about.jsp"' var='"about"'>
<c:param name='"param1"' value='"50"/'>
<c:param name='"param2"' value='"200"/'>
</c:param></c:param></c:url>

[None](&lt;c:out value="${about}")About

(import)


<c:import url='"http://www.example.com/file.txt"/'>
<c:import url='"http://www.example.com/secure/file"'>
<c:param name='"login"' value='"admin"/'>
<c:param name='"pass"' value='"12345"/'>
</c:param></c:param></c:import>
<c:import scope='"page"/' url='"http://www.example.com/file.txt"' var='"dataFile"'>

Functions

Length

Number of item: ${fn:length(sessionScope.products)}

Replace

${fn:replace("kotekot","kot","pies")}

Substring

${fn:substring("Hello Word", 0, -4)}