Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Getting the name thought an unknown parameter

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have this piece of code



As userId I am getting the name. I really dont know from where the parameter userId is coming from . In my mysql DB I have all that data but not a field call userId

The JSP is like this:


Any idea?

Regards,
Isaac
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well have a look at the dao.deleteUser() method?

If you got a "name" then it's probably the user.name field in the form. If this is the case, is username in the DB unique?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ehrn I debug over



userId contains the name I put at the DB

When I debug at the variables tab, I can see the name of the "unknown var" (userId), at the same level as "action", "forward" and response

But I really dont know why it gets the name value.

Also at the variables tab, I can see that the var "name" contains the same value that the var "userId"

Any idea?
 
Sheriff
Posts: 16926
284
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 2 in the above code says you are expecting the request object to have a parameter named "userId".

However, there is no such input element in your form where the name attribute is "userId". The closest you have is this:

Either you change the parameter in the first snippet to "name" or you change the input element in the JSP to have name="userId" so that things come together as you expect. Since you refer to the value as "userId" in your database, you should probably stick with "userId" instead of alternately calling the same thing two different names. That's just confusing.

BTW, your JSP is using scriptlets and you really should not be doing that in new code.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I know this is old code I need to refactorize
 
Sheriff
Posts: 67637
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
In many cases, it's best to leave old, working code be. But in this case, where the scriptlets are just if statements, converting to use <c:if> or <c:choose> is pretty straightforward (assuming that the app is properly set up to use the JSTL and EL already).
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im getting closer to achieve my objective of update my user object, but I have an issue related to the parameter which I exposed previously.

I have this form:



This displays a form which allows the user to modify the text, for ex: the email.


Once the user modifies it it try to to save the new content into the DB.




When I go to the servlet the value of the "nombre" is null, it should be "testName"

Also I am not using



because it doesnt send any value of the form to the Servlet

Any idea?
 
Bear Bibeault
Sheriff
Posts: 67637
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
Have you checked the generated HTML to make sure it matched what you think the JSP should create? And, why the <c:out> to emit a static string?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I checked it, it was of help. Now Iam a step further.

Im using this line of code for send parameters to the Servlet



And yes at the Servlet I get the right value for "userId", but I need to send the whole object "user". My form is like this:




How should I do it, for make this work?

Any idea?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I sort out alittle bit more I was using POST instead of GET method but in my Servlet Im working using GET. After debugging and inspect the request, it looks like there are not parameters there.

But now when I submit this form:



In the Servklet the request doesnt contains the value of "action" which should be "edit" it is null

The Servlet is like:




Any idea?




 
Greenhorn
Posts: 16
jQuery AngularJS Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Isaac,

You cannot send "user" object ! You will have to send them like how you've done for userId.

.

This could be a little cumbersome. I see you're trying to take the values from the link and present it on the edit form, but instead you'll have to fetch the user object again from your update method (based on the userId ) and set the user object in the model for the edit JSP.

Thanks
Srikkanth
 
He's giving us the slip! Quick! Grab this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic