Drew Nichols wrote:
>
> This code will not compile message
> "Attribute back has no value"
>
> <jsp:forward page="
> <%= ( ( request.getAttribute ("back") == null) ) ? "index.jsp" :
> request.getParameter ("back") %>" />
>
> Same as this
>
> <%
> if ( request.getParameter ("back") == null ) {
> %>
> <jsp:forward page="index.jsp" />
> <%
> } else {
> %>
> <jsp:forward page="<%= ( request.getParameter ("back") %>" />
> <%
> }
> %>
>
> Both are the same and will not work.
> Any clues please?
The error message if far from clear, but what it means is that you
use double quotes both to enclose the page attribute value and
within the page attribute value. This confuses the JSP container; it
believes the page attribute value ends at the first double quote,
i.e. just before "back" in your first example. It therefore assumes
that the next string ("back") is another attribute, and reports that
it doesn't have a value (probably because it can't find an equal sign
after the name).
To help the JSP container understand what you mean, you need to
change the code in one of these ways:
1) Use single quotes instead of double quotes to enclose the
attribute value:
<jsp:forward page='<%= ( request.getParameter ("back") %>' />
2) Escape each double quote in the value with a backslash:
<jsp:forward page="<%= ( request.getParameter (\"back\") %>" />
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), 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://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets