• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:setProperty not working for me.

 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tom Katz
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic