Why is Java lying?



Hi,

I'm trying to compile a very simple JSP page on Tomcat 5.5, JDK 1.5

<%@ page import="java.util.*" %>
<%
Object v = new String("b");
session.setAttribute("a", v);

Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String attr = (String) e.nextElement();
String v1 = session.getAttribute(attr);
String v2 = session.getValue(attr);
out.println("attr: " + attr + " v1:" + v1 + " v2:" +
v2);
} // while
%>

but I'm getting this compile error:

An error occurred at line: 2 in the jsp file: /session_vars.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to String

An error occurred at line: 2 in the jsp file: /session_vars.jsp
Generated servlet error:
Type mismatch: cannot convert from Object to String


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


First off, the line number is incorrect (line 2 is "<%") but more
importantly, I thought String extended Object.

Any thoughts? - Dave

.



Relevant Pages

  • Re: PRODUCT calculation in queries
    ... The Microsoft Jet database engine could not find the input table or query ... After pasting it into the code window, choose Compile on the Debug menu. ... Function Product(strField As String, strTable As String, _ ... Dim dblResult As Double ...
    (microsoft.public.access.queries)
  • Re: Help a beginner - simple lowercase to uppercase and so on function
    ... can understand everything but it should take shape with more practice ... it compiles and returns uppercase letters ... in this string!" ... to compile on both. ...
    (comp.lang.c)
  • Re: Compile time string literal substitution to external data file
    ... and these string literals may expose sensitive information ... > I want to use the compile time macros for file name, line number, and ... I'd put a macro and a function like: ...
    (microsoft.public.vc.language)
  • Re: "Ada Gems": Constructor functions
    ... I use Ada 95 to compile and did not receive the BUG ERROR ... function Create_Object (Name: in String) return Object; ... function Construct return Object is ...
    (comp.lang.ada)
  • Re: Error when WebMethod returns a jagged array
    ... compiled the project, and the compile failed. ... assign string[] to a string, ... and see that their code generates Collections instead of jagged arrays. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)