Willy LEGIMAN wrote:
>
> Hi there,
>
> I was trying to pass parameters from one JSP to another using method 1 and 2
> and got the following errors.
> I'm using GNUJSP and I'm wondering whether this has got anything to do with
> the errors.
>
> Method 1
>
> <jsp:forward page="page2.jsp" />
>         <jsp:param name="P_USERNAME" value="SUPER" />
>         <jsp:param name="P_PASSWORD" value="TOMCAT" />
> </jsp:forward>
>
> Error: /myexamples/page1.jsp:9: GNUJSP: illegal parameter tag

AFAIK, GNUJSP is an implementation of JSP 1.0. Support for <jsp:param>
elements nested in the <jsp:forward> body was added in JSP 1.1, so this
works in a JSP 1.1 compliant container.

> Method 2
>
> <%
> String Username = "SUPER";
> String Password = "TOMCAT";
> %>
> <jsp:forward
> page="page2.jsp?P_USERNAME=<%=Username%>&P_PASSWORD=<%=Password%>" />
>
> Error: /myexamples/page1.jsp:8: runtime attribute: multiple expressions and
> mixing of expressions and string constants not permitted:

As the message says, you can't mix strings and expressions like this. Try
this instead:

 <jsp:forward
   page="<%= "page2.jsp?P_USERNAME=" + Username + "&P_PASSWORD=" + Password %>"
 />

You may have problems with this in a JSP 1.0 container though, because the
spec was not clear on how to deal with parameters in the URL.

> Method 3
>
> <jsp:forward page="page2.jsp?P_USERNAME=SUPER&P_PASSWORD=TOMCAT" />
>
> Works (as expected)

I suggest that you upgrade to a JSP 1.1 container, but if that's not an
option for you, there's a forth way that should work in JSP 1.0 as well:
use request *attributes* as opposed to *parameters*. Something like this:

  <%
    request.setAttribute("P_USERNAME", "SUPER");
    request.setAttribute("P_PASSWORD", "TOMCAT");
  %>

In page2.jsp, you can retrieve them like this:

  <%
    String user = (String) request.getAttribute("P_USERNAME");
    String pw = (String) request.getAttribute("P_PASSWORD");
  %>

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

Reply via email to