Robert S. Sfeir wrote: > > I'm trying to use proper XML syntax to build my JSP pages and am > following the specs form the Sun site. I keep getting an error and am > not sure if it's due to the JBoss/Jetty implementation I'm using (JBoss > 3.0.1 / Jetty 4.01) or if I'm doing something wrong which I can't figure > out. > > The error I get is pretty lame and doesn't say much: > > HTTP ERROR: 500 /index.jsp(42,-1) Use "<" for "<" in attribute values. > > and the line it's croking on is: <a > href="<jsp:expression>response.encodeURL("logout- > action.do")</jsp:expression>">Logout</a> > > The full scriptlet block looks like this: > > <jsp:scriptlet> > if(session.getAttribute("person") == null) > { > </jsp:scriptlet> > <a HREF="login.jsp">Login</a> > <jsp:scriptlet> > } > else > { > </jsp:scriptlet> > <a href="<jsp:expression>response.encodeURL("logout- > action.do")</jsp:expression>">Logout</a> > <jsp:scriptlet> > } > </jsp:scriptlet> > > > what gives?
The XML syntax is primarily intended for tools that generate or parse JSP documents, because writing it by hand is messy. The reason is that an XML document must be well-formed; no elements in attributes, all start tags followed by end tags, nested correctly, etc. When you mix HTML template data and XML JSP elements, it's not always obvious how to apply the well-formedness rules. In your example, the main problem is that you try to use an element (<jsp:expression>) as the attribute value of another (<a>); it doesn't matter that one is HTML and one is JSP. An additional complication is that you want to insert a dynamic value between quotes, ending up with the start quote in one place and the end quote in another. This also confuses the XML parser unless you tell it explicitly that you know what you're doing. To fix both these problems, you need to write the snippet like this: <jsp:text><![CDATA[<a href="]]></jsp:text> <jsp:expression>response.encodeURL("logout-action.do")</jsp:expression> <jsp:text><![CDATA[">Logout</a>]]></jsp:text> The <jsp:text> element separates the HTML template text from the JSP element, the CDATA sections takes care of the quote problem. I strongly recommend that you stick to the classic syntax since the XML syntax really just complicates life when you write the pages manually. Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com JavaServer Pages http://TheJSPBook.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com