1

I want to print the two values by using single jsp expression tag is it possible?

<% int a=5;
   int b=10;
   int c=a+b;    

%>
 The values of a,b and c are: <%=a,b,c%>

I have to individually write jsp expression for each variables or the above code is correct.. in jsp.

Thanks..

user460920
  • 887
  • 5
  • 17
  • 27
  • In future questions, post as well the results and errors which you're getting. Do not ask "Is it possible?". This testifies zero effort from your side. Just try and run it and post the error/exception message, if any. – BalusC Feb 27 '12 at 16:48

2 Answers2

3

You'd need to String-concatenate them.

<%= a + "," + b + "," + c %>

Or display them individually.

<%= a %>,<%= b %>,<%= c %>

Note that what you're doing is an oldschool way of using JSPs. Consider using EL.

${a},${b},${c}

Update as per the comments, you seem to now want print the comma at all, in contrary to what you initially presented in the question, here are the examples in the same order without printing the comma:

<%= a + "" + b + "" + c %>
<%= a %><%= b %><%= c %>
${a}${b}${c}
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • ok..thanks i will try i am new..and i just started learning it..but can you help me out with the old method only that if i have to print the values of a b and c i don't want "," comma in between then also i need to use concate + ?? – user460920 Feb 27 '12 at 16:50
  • 1
    If you don't want to print the comma, just remove it like so: `<%= a + "" + b + "" + c %>` or `<%= a %><%= b %><%= c %>` (or replace by a space). Makes sense, does it? – BalusC Feb 27 '12 at 16:51
0

No it does not. you will have to write them individually in the following manner ......

<%=a%>
<%=b%>
<%=c%>
Nitin Jain
  • 133
  • 2
  • 12