I use to pass data between *.java and *.jsp, since this is a MVC framework, it will go by the *.java first. so i used request.getSession().setAttribute("test", "01010101010") to save the value, and then in *.jsp, use request.getSession().getAttribute("test") to get value. But it returns a strange string "682342348" all the time. what's UP?????
+1
A:
Try casting the value to a string when you get it out of session:
String.valueOf(request.getSession().getAttribute("test"));
ironsam
2009-08-04 07:03:43
A:
It's possible that your java class and your JSP are getting different session objects somehow. You could try comparing the value you get back from session.getId()
to make sure they're the same.
However, if all you're trying to do is pass objects from java class to JSP, then you may not need to use the session at all. Instead, store the data as a request attribute:
request.setAttribute("test", "01010101010")
skaffman
2009-08-04 07:07:56
Yeah, i used this before, but it also return the error data. and when i try to use request.getAttribute("test").toString(), it throw out a exception
MemoryLeak
2009-08-04 07:15:29
+1
A:
This might be a javascript question now, try adding quotes around the value of the alert
parameter.
Change this:
<script>alert(<%=request.getAttribute("test")%>);</script>
To this:
<script>alert('<%=request.getAttribute("test")%>');</script>
ironsam
2009-08-04 07:35:26