Search code examples
jspstrutsjstldisplaytag

Jsp scriplets with taglibs


Below is my code snippet I am using scriplets with taglibs.

 <display:column title="Modify">
        <%String userType=(String)session.getAttribute("userType");
        if(userType.equalsIgnoreCase("D"))
        {
        %>

     <html:link action="/deleteOwner.do?type=del&owner_id=${data.owner_id}">Delete</html:link> 

     <%} else if(userType.equalsIgnoreCase("A")){%>

        <c:if test="${data.type == 'A'}">  

     <html:link action="/deleteOwner.do?type=del&owner_id=${data.owner_id}">Delete</html:link> 
        </c:if>
                </display:column>

        <%}%>

But I am getting

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 280 in the generated java file
Syntax error, insert "while ( Expression ) ;" to complete DoStatement

Solution

  • Try not to mix scriptlets with jstl. It will only cause you headaches. Instead replace your if/else statements with choose/when/otherwise statements.

    In the case of your equalsIgnoreCase() statements, you could simply call fn:toUpperCase on your userType to do the comparison.

    Using EL you can pull the userType argument using ${userType}