Problem receiving variables from a servlet
In doPost I set a variable, req.setAttribute("uname",user); then I forward it,
req.getRequestDispatcher("/page.jsp").forward(req, resp);
I'm trying to access this variable I set in my JSP. <%=uname%> gives me an org.apache.jasper.JasperException: Unable to compile class for JSP error. <%request.getParameter("uname"); %> gives me null.
In my servlet I print out uname and it does print out the correct user name. Can anyone see what I am doing wrong?
[489 byte] By [
ner0a] at [2007-11-27 4:43:15]

# 3
<%= uname %> looks for a scriptlet variable on the page called "uname"
That has nothing to do with request attributes.
If you have a JSP2.0 container (Tomcat 5) then the EL expression ${uname} is pretty much equivalent to request.getAttribute("uname") (its actually pageContext.findAttribute("uname"))
Passing this variable into a js function?
By this I presume you mean "generating static javascript code onto the page"
You remember that java/jsp code only runs on the server right?
# 4
I looked into pageContext and got it to work using<% String user = (String)request.getAttribute("uname");pageContext.setAttribute("user",user); %>and in my js I can call <%=pageContext.getAttribute("user") %>and it works.
ner0a at 2007-7-12 9:54:59 >
