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 th开发者_如何学Goese 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")); %>
Expressions are used to print some value on the page, whereas scriptlets are statements. Your best bet is to go and check the generated class.
精彩评论