aspose file tools*
The moose likes JSP and the fly likes jsp:setProperty not working for me. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:setProperty not working for me." Watch "jsp:setProperty not working for me." New topic
Author

jsp:setProperty not working for me.

Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
I may be barking up the wrong tree here or missing something obvious... but here's what I'm trying to do:

-set a session attribute in a servlet with an object
..later in a JSP
-trying to call jsp:setProperty, instantiating the same object using useBean (mainly for saving a lot of coding when it comes to setting the beans fields with the request parameters)

The problem occurs later, setProperty doesnt seem to call the set function for the parameters (as far as I know I have the naming conventions for the bean correct)

It looks to me like useBean calls:

pageContext.getAttribute("objectName", PageContext.SESSION_SCOPE);

so I wont be able access session attributes set in the servlet context??

Anyone know of a way around this? Or what I'm doing wrong?

Yes, the JSP has 'session=true' set...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Could you either re-word the question or post your code?
I'm not exactly sure what the question is.

In the mean time, if you want an example of a JSP with a useBean tag, go to:
http://simple.souther.us and download SimpleBean.war.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
Sorry, I'll try to be more concise and clear and post the appropriate code... (although I"ve refactored a bit and dont have the exact code handy at the moment.)

Servlet Code:>>>>>>>>>>>>>>>>>>>>>

Mqmd mqmd = new Mqmd();
request.getSession().setAttribute("Mqmd", mqmd);
<<<<<<<<<<<<<<<<<<<<<<<<<<<

JSP code:>>>>>>>>>>>>>>>>>>>>>

<jsp:useBean id="mqmd" class="Mqmd" scope="session"/>
// will this useBean call access the session attribute set in servlet???
<jsp:setProperty name="mqmd" property="*"/>

request.getSession().setAttribute("Mqmd", mqmd); // re-set session attr
// after setting fields
<<<<<<<<<<<<<<<<<<<<<<<<<<<
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Tom Katz:

<jsp:useBean id="mqmd" class="Mqmd" scope="session"/>
// will this useBean call access the session attribute set in servlet???

Yes. It will also instanciate it for you if one isn't present in the scope specified (in this case: session). You will need to package your beans in order for the JVM to find it. It used to be possible to run with un-packaged beans but this changed in Java 1.4.
The class attribute will need to be fully qualified with the package name.

Originally posted by Tom Katz:
request.getSession().setAttribute("Mqmd", mqmd); // re-set session attr
// after setting fields

This isn't necessary but it doesn't hurt to leave it in for clarity.
[ February 07, 2005: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Wait... Here's the problem:


The spelling and capitalization have to match exactly in order for the useBean tag to locate your exising object.

Again, if one isn't found with that name, in that scope, the useBean tag will instanciate a new one for you.
[ February 07, 2005: Message edited by: Ben Souther ]
 
 
subject: jsp:setProperty not working for me.