I find myself needing to learn a little bit of JSP for my Software Engineering class. One of our homework questions is as follows:
What are the output of these two code snippets if the parameter "myText" has the
value "JSP is fun"?
<% request.getParameter("myText"); %>
...and...
<%= request.getParameter("myText") %>
Here's my answer:
The first line of code snippet should properly return "JSP is Fun".
The second line of code should also properly return "JSP is Fun" as it is an expression, which means it does not require a semi-colon to function correctly (and would not work with one).
Am I missing something glaringly obvious, or is there really nothing more to this relatively simple question?
The first one will not print anything since it's surrounded with a <% ... %> tag.
The second one will print JSP is fun since it's surrounded with a <%= %> tag.
The = part in the tag indicates that it should print out the return value of the code inside the tag.
On a side note, the first code snippet can also print out the value JSP is fun if it was written as such:
<% out.println(request.getParameter("myText")); %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With