Re: Why is Java lying?



laredotornado@xxxxxxxxxxx wrote:
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);
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
%>

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.
Don't ask me why the compiler says "line: 2", although it actually seems to be line 10.

Any thoughts? - Dave


--
Thomas
.



Relevant Pages

  • Re: JSP Java truncates string at the first non-english character
    ... >> with swedish or danish ÅÄÖ characters, the string is cut where the ... >> which returns a servlet error. ...
    (comp.lang.java)
  • Re: Why is Java lying?
    ... I'm trying to compile a very simple JSP page on Tomcat 5.5, ... String attr = e.nextElement; ... Generated servlet error: ... Type mismatch: cannot convert from Object to String ...
    (comp.lang.java.programmer)
  • Why is Java lying?
    ... I'm trying to compile a very simple JSP page on Tomcat 5.5, ... String attr = e.nextElement; ... Generated servlet error: ... Type mismatch: cannot convert from Object to String ...
    (comp.lang.java.programmer)
  • Re: Why is Java lying?
    ... You have to cast from Object to String. ... Generated servlet error: ... Type mismatch: cannot convert from Object to String ...
    (comp.lang.java.programmer)
  • CDO, Active Directory and Mail Enable
    ... I've added a comment indicating which line generates the type mismatch ... Function CreateDL(strPath As String, strGroupName As String, ... ' CreateDL(strPath As String, strGroupName As String, strSamAcctName As ... Dim iAdCont As IADsContainer ...
    (microsoft.public.exchange.development)