1

I have an ajax call to a jsp page with certain data.

$.ajax({

    type: "POST",

    url: "jsp/order.jsp",
    data: {
        "dishId"                    :   id,
        "dishPrice"                 :   price,
        "dishName"                  :   name

          },
    success: function(msg) {
        alert(msg);
          }
    });

I want to read the data in the order.jsp using jstl. However I am not able to do that using the following statements.

<c:out value='${dishName}' />
<c:out value='${dishId}' /> 

I know it can be done using scriptlets but wanted to do it using jstl.

adarsh hegde
  • 1,353
  • 2
  • 21
  • 43

1 Answers1

0

All HTTP request parameters are in EL available via implicit ${param} mapping.

So, this should do:

<c:out value="${param.dishName}" />
<c:out value="${param.dishId}" /> 

See also:


Unrelated to the concrete problem, do note that there's quite a difference between "JSTL" and "EL". Those <c:xxx> things are JSTL tags. Those ${...} things is EL. You can also use EL standalone:

${param.dishName}
${param.dishId}

However, that opens a potential XSS attack hole, hence the need for <c:out> to escape it.

And, you'd better use a servlet instead of a JSP to deal with HTTP requests. See also How to use Servlets and Ajax?.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555