Can I use object in JSP which is created in servlet?
Dave Thunder
Greenhorn
Joined: Dec 03, 2005
Posts: 22
posted
0
How should I access object, which I have created in servlet?
Servlet handles the requests(controller) and forwards to requested jsp page. Some of the jsp pages need EJB objects. When i create an ejb object in servlet and then forward the request to jsp, how can i access the object in jsp ?
This should be MVC - based application, like JSP-Servlet-EJB.
Thanks! [ December 07, 2005: Message edited by: Dave Thunder ]
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
You can attach any reference to the request - see the JavaDocs for javax.servlet.ServletRequest - specifically setAttribute and getAttribute. Bill
Getting NULL. Should be correct or what ? EDIT : I just don't get it. Do I have to import anything to jsp to use request.getAttribute() ? I think no...
[ December 07, 2005: Message edited by: Dave Thunder ] [ December 07, 2005: Message edited by: Dave Thunder ]
sudhir kamath
Greenhorn
Joined: Mar 07, 2002
Posts: 16
posted
0
first check whether you are directed to you jsp you are pointing.if you are able to direct it you should be able to get it.
And when I set my values in session for example, I can get them in jsp. I don't know. Maybe I will use session instead of request for setting attributes.
You're only setting the request attribute when you forward to the error.jsp page. When you forward to the tere.jsp page you aren't setting any request attributes. Was your problem with the error.jsp?
Dave Thunder
Greenhorn
Joined: Dec 03, 2005
Posts: 22
posted
0
Yes, my problem is with error.jsp here. I only set attributes here for one case, it is for trying. But it is correct, right? Should be.
And here is error.jsp :
[ December 11, 2005: Message edited by: Dave Thunder ]
Dave Thunder
Greenhorn
Joined: Dec 03, 2005
Posts: 22
posted
0
This is some kind of mystics.
Taras Tovstenko
Greenhorn
Joined: Dec 20, 2005
Posts: 1
posted
0
Hi. I found the bug! when you're putting your object as request attribute you use something like this: request.setAttribute("name", new Object);
in your JSP when you trying to get attribute you use: <%= (String)session.getAttribute("nimi")%> rewrite that part of code to something like this: <%= (String)request.getAttribute("nimi")%>
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Can I use object in JSP which is created in servlet?