Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the name thought an unknown parameter  RSS feed

 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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
 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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?
 
Junilu Lacar
Sheriff
Posts: 10879
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I know this is old code I need to refactorize
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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).
 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 <cut> to emit a static string?
 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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?
 
Isaac Ferguson
Ranch Hand
Posts: 1054
3
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • 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?




 
Srikkanth Mohansundaram
Greenhorn
Posts: 16
AngularJS Chrome jQuery
  • Mark post as helpful
  • send pies
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!