Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML syntax for jsp

 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is following a valid jsp syntx ?<jsp:expression>output</jsp:expression>
shouldn't the word output be enclosed in quotes ?
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is a variable named as output defined before this (either as a scriptlet var or as a declaration var) , this code will work fine. Meaning the value of a varibale 'output' will be written to JspWriter.
For example the following jsp will work fine.

If there is no variable defined before, then we will get a compilation error.
If we just want to get this String "output" itself to browser then we can code like this .
<jsp:expression>
"output"
</jsp:expression>
Regards,
Maha Anna
[ December 13, 2002: Message edited by: Maha Annadurai ]
 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
version="1.2">
<jsp:scriptlet>
String output ="Hello World!";
</jsp:scriptlet>
<jsp:expression>
output
</jsp:expression>
</jsp:root>
I think, in above code, output should be enclosed in %= output %, because this is a request time attribute expression.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above code has got a valid jsp expression. Note that it is NOT a request time attribute expression. A request time attribute expression is something like this.

Regards,
Maha Anna
[ December 16, 2002: Message edited by: maha anna ]
 
Rasika Chitnis
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it, thanks.
 
Dexter Blick
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if your intent is to print the word "output" you could also use the <jsp:text> tag...
<jsp:text>output</jsp:text>
 
Bernd Stransky
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A) JSP expression add some data to the output stream.
XML style:
<jsp:expression> other </jsp:expression>
JSP style:
<%= other %>
-> adds the value of variable other to output stream.

B) Request time attribute expressions allow to pass dynamic values to actions like jsp:include, beans or custom tags.
XML style: "%= other %"
example: <jsp:include page="%= pageURL %" />
JSP style: "<%= other %>"
example: <jsp:include page="<%= pageURL %>" />
-> passes the value of variable other ot include action.

So JSP style uses <%= ... %> in both cases.
Hope this helps,
Bernd
SCJP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic