> Hi,
>
[quoted text clipped - 33 lines]
> First off, the line number is incorrect (line 2 is "<%") but more
> importantly, I thought String extended Object.
Yes, but you are casting the other way - and in some places you do not
even have the cast (String v2 = session.getValue(attr);).
robert
> I'm trying to compile a very simple JSP page on Tomcat 5.5, JDK 1.5
>
[quoted text clipped - 8 lines]
> String v1 = session.getAttribute(attr);
> String v2 = session.getValue(attr);
I suspect the JSP compiler complains about the line above, because
HttpSession.getValue is declared as
public Object getValue(String name)
but not as
public String getValue(String name)
See
<http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html>.
> out.println("attr: " + attr + " v1:" + v1 + " v2:" + v2);
> } // while
[quoted text clipped - 18 lines]
> First off, the line number is incorrect (line 2 is "<%") but more
> importantly, I thought String extended Object.
Don't ask me why the compiler says "line: 2", although it actually seems
to be line 10.
> Any thoughts? - Dave

Signature
Thomas
dantarion@gmail.com - 28 Nov 2006 20:20 GMT
You have to cast from Object to String.
java does not know that that "Object" is a "String".
it does know that "String"s are "Object"s.
You have to cast whenever you go from general->specific
String v2 = (String) session.getValue(attr);
On Nov 28, 12:12 pm, Thomas Fritsch <i.dont.like.s...@invalid.com>
wrote:
> laredotorn...@zipmail.com wrote:
> > I'm trying to compile a very simple JSP page on Tomcat 5.5, JDK 1.5
[quoted text clipped - 42 lines]
> > Any thoughts? - Dave--
> Thomas
Karl Uppiano - 28 Nov 2006 21:32 GMT
> java does not know that that "Object" is a "String".
> it does know that "String"s are "Object"s.
I know this doesn't answer the basic question, but if it is just the string
you want,
String attr = e.nextElement().toString();
should work without casting.
Lew - 02 Dec 2006 07:23 GMT
laredotornado@zipmail.com wrote:
>> I'm trying to compile a very simple JSP page on Tomcat 5.5, JDK 1.5
>>
[quoted text clipped - 17 lines]
>> Generated servlet error:
>> Type mismatch: cannot convert from Object to String
>> First off, the line number is incorrect (line 2 is "<%")
> Don't ask me why the compiler says "line: 2", although it actually seems
> to be line 10.
Perhaps in a JSP the entire content from <% to %> is considered one line?
NttpSession.getValue() is deprecated.
- Lew
jcsnippets.atspace.com - 05 Dec 2006 13:41 GMT
<snip>
>> Don't ask me why the compiler says "line: 2", although it actually
>> seems to be line 10.
>
> Perhaps in a JSP the entire content from <% to %> is considered one
> line?
A JSP cannot be compiled, since it is not Java code. Your web/app server
will create a .java file from the JSP file, which in turn will be compiled
into a servlet.
Look up the .java file for your JSP file, and you will see that those line
numbers actually are correct - they don't refer to the JSP, but to the
accompanying .java file.
Best regards,
JayCee

Signature
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks
Patricia Shanahan - 05 Dec 2006 14:58 GMT
> <snip>
>>> Don't ask me why the compiler says "line: 2", although it actually
[quoted text clipped - 9 lines]
> numbers actually are correct - they don't refer to the JSP, but to the
> accompanying .java file.
C has a system for specifying user-meaningful file names and line
numbers in automatically generated code. Maybe Java should have an
annotation to do the same job.
Patricia