Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between c:out and print the output using $

Tags:

java

jsp

jstl

In JSTL there are two ways to print the output -

<H1><c:out value="${theOutput}" /></H1>

AND

<H1>${theOutput}</H1>

What is the difference? And which one is preferred way?

Thanks.

like image 278
Saurabh Avatar asked Aug 19 '13 08:08

Saurabh


People also ask

What is difference between printf and print?

The difference between printf and print is the format argument. This is an expression whose value is taken as a string; it specifies how to output each of the other arguments. It is called the format string. The format string is very similar to that in the ISO C library function printf() .

What is the use of C OUT?

The cout object is used to display the output to the standard output device.


1 Answers

Both methods c:out and JSP EL will display output to the page, however there is one major difference. The c:out tag will automatically escape xml output which can prevent cross site scripting. Using JSP EL (the second option) will not escape the output.

When displaying data which has been inputted by a user use the c:out tag instead of JSP EL to prevent any malicious data input from displaying on the page.

like image 57
Kevin Bowersox Avatar answered Oct 26 '22 13:10

Kevin Bowersox