ict1991
ict1991

Reputation: 2110

Why is the Java code in JSP generating an error?

I'm trying to input some java code in my jsp however the following exception is being generated :

org.apache.jasper.JasperException: /Home.jsp(31,8) PWC6203: Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed

My jsp contains an if statement and will check data. If it matches, some html code is displayed, otherwise, another code is displayed

<% String username = session.getAttribute("loggedIn").toString();
               String actual = "${message.message}";
               if(username.equals(actual)){%>
                <div style="background-color:#fff380;"> 
                ...
                </div>
            <%} else { %>
                <div> 
                ...
                </div>
            <%}%>

Does anyone know why this type of error is being generated please? thanks a lot

Upvotes: 1

Views: 5546

Answers (1)

JB Nizet
JB Nizet

Reputation: 692281

Sciptlet usage has probably been configured invalid (see http://www.java-samples.com/showtutorial.php?tutorialid=548). And this choice was a wise choice, because scriptlets shouldn't be used in JSPs anymore. Use the JSTL and the EL:

<c:choose>
    <c:when test="${loggedIn == message.message}">
        ...
    </c:when>
    <c:otherwise>
        ...
    </c:otherwise>
</c:choose>

Moreover, even if scriplet was valid, you can't use the JSP EL inside scriptlet code.

Upvotes: 2

Related Questions