• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

jsp:useBean returns nulls

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having a problem with a Bean I created for accepting entries via "post" in a form on a JSP page. All I get are null values, and I can't find where I'm going wrong.
After reading Bear's article entitled "Scriptless JSP Pages: The Front Man" from the May 2006 journal, I started working to move the logic for handling the form data off the primary page (something which was done often in the code here, and from where i picked up the bad habit myself). So, I have the following code on the page containing the form:


The receiving page (processReferee.jsp) has the following code:


The bean itself is named NewReferee, and has the format:



I realize that passing the POST to a JSP is poor form (as is the system.out.println), but this is just to test that I'm getting values passed over. I'm going to fix that after I get this issue resolved. The page processReferee.jsp will be changed to a servlet which calls another part of the "referral" class (one I've yet to write), passing it a linkedHashMap of name/value pairs, and then redirect to the original data entry page, ready to accept more entries.
I also set the scope to "session," with no change. Can anyone point me in the direction of what I'm missing?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lou Umile wrote:All I get are null values


Do the result page show name: null?
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm kinda mystified as to why you are taking time on this. If you know that it's not the best way to do it, why bother? Anything that might be wrong (a quick inspection didn't make anything jump out at me -- I assume that there's a form control with the name name in the form?) isn't going to be any issue when you do this within a servlet. So it's all rather moot from a practicality point of view.

Unless, of course you want to academically find out what's going on for your own information.

By the way, thanks for taking the time to read the article.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're printing something called "newReferee.etc" but don't appear to be defining it anywhere; the useBean is naming the bean "newEntry".
 
Lou Umile
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonas: exactly. It gives me "name: null" in Catalina.out.

Bear: the reason I didn't just do this as a servlet is that I need to learn to write servlets. I've basically been given an orphaned project from someone who left the company. While I'm ok with java in general, I'm trying to get time to teach myself servlet programming. As for the article, it gave me a strong idea of where to proceed with the basic design of this project. Before, everything was passed around with appending arguments to the end of URLs and using GET. I'm in the process of changing that. As for the field "name," it's actually "lName" and "fName," which I truncated for the purpose of brevity in my example.

David: My typo. Since I don't want to have to worry about my employer getting upset over me posting this, I sanitized the names. It should read "newEntry.getName()."
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I cannot imagine an employer getting upset over revealing what names you use for request parameters, I've heard of stranger things.

In any case, that kind of leaves us in limbo because without the actual code, it's hard to tell what's really going on.

If you cannot show us the actual code, all we'll be able to do is give you some debugging tips on what to look for. For example, use an HTTP sniffing tool to make sure that the request parameters being submitted by the form match your expectations, and match the expectations of the target bean.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing to do would be to verify that an instance of NewReferee does not already exist in request scope under the same id. If it does, then the body of <jsp:useBean> will be ignored.
 
Lou Umile
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kris: That's actually something that was concerning me, so I checked, and sure enough, it occurs even without an instance of NewReferee initialized. Of course, I only caught this because one of the pages I was reading on this subject mentioned that if there's an instance existing, it will ignore the body. I was starting to think that the information about whether it would initialize with another instance existing was an example of how web resources sometimes give bad information. Thank you for the heads up, and confirming what I read.

Bear: I know it seems odd, but people here have gotten in trouble for what I thought were innocuous things, so I'm extra careful. As for needing the actual code to offer suggestions of what to try, this is the actual code. I simply used string substitution to change variable and package names, because I knew that asking any more vague of a question wouldn't help. I'll edit that code example to fix my typo, as well.

Edited to add: I seem to have exceeded the time constraint for editing the entry. Is there another way I can correct it?
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just post any changes as a reply noting that you are doing so.
 
Lou Umile
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, thank you. I didn't want to clutter things up.

processReferee.jsp *SHOULD* read:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic