• 7
name Punditsdkoslkdosdkoskdo

How to avoid Java code in JSP records?

I'm new to Java EE and I know that something like the following three lines

<%= x+1 %>
<%= request.getParameter("name") %>
<%! counter++; %>

is an old school way of coding and in JSP version 2 there exists a method to avoid Java code in JSP files. Can someone please tell me the alternative JSP 2 lines, and what this technique is called?

You can use JSTL tags together with EL expressions to avoid intermixing Java and HTML code:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="" prefix="c" %>
<%@ taglib uri="" prefix="fmt" %>

        <c:out value="${x + 1}" />
        <c:out value="${}" />
        // and so on

  • 0
Reply Report
  • 0

JSTL offers tags for conditionals, loops, sets, gets, etc. For example:

<c:if test="${someAttribute == 'something'}">

JSTL works with request attributes - they are most often set in the request by a Servlet, which forwards to the JSP.

  • 0
Reply Report

Related Questions

Trending Tags