Can you parse a Java object as a parameter?

Hi,

I thinking I'm asking something fundamental here, but I was wondering if there was any way of creating a java object in a java servlet and then passing that object to a jsp page (if the object is *not* a bean)?

For example, I want to create an object of type com.jae.jaeQuestion.Question in QServlet and send this object to a jsp page to access its accessor methods. (I cannot make Question into a bean as it accesses a lot of backend data sources whcih are generated on the fly and have thousands of different results with no unique key).

I tried in the Servlet:

session.setAttribute("question", actualQuestion);

Where actualQuestion is of type Question but then I get an error on the JSP because it can't convert the String question to a Question (I was casting it).

Is the only way to do it, have the servlet access all the accesor methods and chuck the results into parameters?

Basically, can parameters of a session only be strings?

Thanks in advance

[1017 byte] By [lil_alfy_aliena] at [2007-11-26 16:52:45]
# 1

setAttribute() stores an Object, not only a String. So if you put a Question object in the session, then in the JSP you can retrieve a Question object. If you put a String in there in the servlet, you get a String in the JSP.

If your object is of the wrong type then you are simply storing the wrong type.

Here is the javadoc for setAttribute() :

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String,%20java.lang.Object)

gimbal2a at 2007-7-8 23:20:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...