| Author |
Servlet runs, but doesn't do anything
|
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
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.
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
Are you sure that this if check is passing? If it doesn't, it doesn't look like your name will be updated. Corey
|
SCJP Tipline, etc.
|
 |
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
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
Joined: Dec 20, 2001
Posts: 3271
|
|
Try using this is your JSP: as opposed to: Let me know if that fixes the problem. Corey
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
request.getParameter("txtName") is retrieving the original request parameter unchanged.
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
Garann Means
Ranch Hand
Joined: Jan 28, 2002
Posts: 214
|
|
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
Joined: Dec 20, 2001
Posts: 3271
|
|
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
Joined: Jan 28, 2002
Posts: 214
|
|
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
Joined: Dec 20, 2001
Posts: 3271
|
|
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
|
 |
 |
|
|
subject: Servlet runs, but doesn't do anything
|
|
|