• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet runs, but doesn't do anything

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JSP calling a servlet calling a bean, sending a request to a final JSP. When I submit the first JSP, I can see that the servlet runs just like it should by sending statuc messages to stdout, but when the last JSP loads up, it's like the servlet never ran.
All the servlet does is check the value of a submitted field and, if it contains certain values, alter that string and return it. I can see it altering the string, but the JSP gets passed the string as it was originally entered.
Here's where the data gets added to the last JSP:

And this is the servlet:

Any help? Thanks..
g.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that this if check is passing?

If it doesn't, it doesn't look like your name will be updated.
Corey
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey,
Yes, the check passes and changes the newName String. The newName variable is exactly what is should be for both variables in the Vector from the bean and those not in the bean. But the new data doesn't seem to be passed to the JSP.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using this is your JSP:

as opposed to:

Let me know if that fixes the problem.
Corey
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
request.getParameter("txtName")
is retrieving the original request parameter unchanged.
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey and Bosun,
Good call, that fixed it. I'd tried that initially, but didn't cast it to a String, so it was producing a blank HTML page, leading me to believe I was on the wrong track. You actually need to do this:

So why does that fix it? Are parameters form data exclusively? The spec didn't quite clear it up for me - if anyone has a link to a good article, I'd love to see it.
Thanks!
g.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay - a couple things here. First of all, the request object extends javax.servlet.ServletRequest. The getAttribute method returns an Object, not a String. That's why, in general, you'll either want to cast what you get back (as you did) or, perhaps, call toString() on it (if you want to assign it to a String, at least).
Also, you were setting the data in the request with a call to setAttribute, but you were originally trying to read it by using getParameter. As far as I know, the request object has a set of attributes and a set of parameters and they are two separate lists. (Someone please correct me if I'm wrong about this.) Therefore, if you were using getParamater to try to get something in the attribute list, you wouldn't get what you were after. I should have caught that sooner. Sorry.
Corey
[ May 21, 2002: Message edited by: Corey McGlone ]
 
Garann Means
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey,
I was actually requesting inaformation about what the Parameters list is for and what the Attributes list is for. That is, does the Parameters list hold only form data?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the API Spec for getParameter:


Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.


As far as I know, the form data is automatically put into the parameter list. From the description above, it sounds like there might, potentially, be some other information there, as well.
You can, however, add whatever objects you'd like to the request through the use of the setAttribute method. There is no setParameter method so, if you're ever trying to retrieve something from the request that you put there, you should be getting it from the attribute list.
I hope that helps,
Corey
 
reply
    Bookmark Topic Watch Topic
  • New Topic