This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Cannot retrieve ID from GET method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot retrieve ID from GET method" Watch "Cannot retrieve ID from GET method" New topic

Cannot retrieve ID from GET method

Fandy Akhmad
Ranch Hand

Joined: Nov 26, 2011
Posts: 32

Dear, master Java

I try to make CRUD Application using Struts2 , but there is problem while i edit data.
Problem is : Id cannot retrieve, its return 0(zero)

I get Id using this code (velocity) :

Then I try to ouput in console :

But Ouput : 0

This is my entity [] :

This my action []

And the last one my view, [view.vm]

Anyone, please help me,

Thanks before..
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Ha, interesting

1. You get 0 since your ID is of type int. May be you are not setting the value of Id. Where are you setting the value for this?
2. I guess "./view.action?id=$" would be taken as a single entity and does not evaluate the value of $ I didnt work in struts 2 and hence do not know exact conventions/syntax maybe try single quotes like "...?id='$'" - again this might work or may not, not sure.
3. ------------not at all important, but your code is very much vulnerable to SQL injection

Have Fun with Java
little,little.. little by little makes a lot..
It is sorta covered in the JavaRanch Style Guide.
subject: Cannot retrieve ID from GET method
Similar Threads
Using String() method to initialize variable
Problem with a Managed Bean
JTable doesn't show new model after adding new row
JAXB Saving and loading a generic List of type T to/from XML
file cannot be resolved to a type