On Tue, 18 Dec 2001, Mark Galbreath wrote:
> Well, Milt, I will certainly defer to you in Java expertise. Thing
> is, I was just wrestling with a problem very close to this yesterday
> and there is (a) a definite difference between a string (literal)
> and a String (object) when it comes to some of the API methods.
That could be, but I'd like to see the specifics of it to get a better
idea of what is really going on. In my experience (which I'm certain
isn't comprehensive), string literals can be used anywhere string
objects can.
> (b) Equals() is a strange beast in any event and, IMHO should be
> more clearly defined at the Object level (or at least give us an
I'm not really sure what you mean here.
> interface for it). "Application" in the JSP spec seems to me the
> equivalent of "session" in the Servlet spec, though in the JSP spec
> "session" is not much more than a page context.
No, JSP's "application" is the same as servlet's "context". But my
question there was more specific, I was asking how his servlet
identifier/varible application was defined (he sent me email privately
answering that). application is a pre-defined identifier/varible that
can be used in JSP's, so it's clear what it is there.
> (c) We know that
> equals() will accept a literal, but the J2EE API states specifically
> that "getAttribute" takes a string as its first parameter and an
> object as its second. Hence, you access the attribute by its
But a String *is* an Object.
> literal name, which brings the object into scope and then you need
> cast the object to its type before accessing its properties.
True. You'll need to cast it to a String before you can use it when
doing a get (well, only if you're doing String things on it, you can
still do Object things on it -- like printing it -- without casting
it). But you don't need to do anything like that when doing a set
(it's just like inserting and removing things from a Vector). So this
isn't relevant to his problem.
> ----- Original Message -----
> From: "Milt Epstein" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, December 18, 2001 6:55 PM
> Subject: Re: Communication between JSP and servlets
>
>
> > On Tue, 18 Dec 2001, Mark Galbreath wrote:
> >
> > > Look at the API - setAttribute() takes a String and an Object, not 2
> > > Strings. Try something like:
> > >
> > > String errorMessage = "NO Error Message";
> > > application.setAttribute( "errorMessage", errorMessage);
> >
> > Mark, I think you're losing it :-).
> >
> > Surely a double quoted string literal is a String object (or is
> > translated/converted to a String object -- I'm not surely exactly how
> > the language spec technically deals with it.) How else could you do
> > things like:
> >
> > "a".equals("b")
> >
> > And of course, if that was the problem, the code below wouldn't even
> > compile.
> >
> > Not that I do know what the problem is :-).
> >
> > But here's a quesiton: application is a pre-defined identifier in
> > JSPs, but what is the application in the line of servlet code below?
> >
> >
> > > -----Original Message-----
> > > From: Jim Lindsay
> > > Sent: Tuesday, December 18, 2001 2:49 PM
> > >
> > > I am not able to get session or application scope tracking to work for
> some
> > > reason. Currently the code is trying to use
> > > application tracking, but I know I should be using session tracking for
> > > items that are for the user session.
> > >
> > > In my userLoggidIn.jsp page I have:
> > > Error Message = < <%= application.getAttribute("errorMessage") %>
> >
> > >
> > > In my servlet I have:
> > > application.setAttribute("errorMessage", "NO error message");
> > >
> > > esponse.sendRedirect( response.encodeRedirectURL("/userLoggedIn.jsp");
> > >
> > > The output is *always*: "Error Message = < null >". What the heck am I
> > > doing wrong?
> > >
> >
>
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html