• 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

Not able to retrieve values on the click of button at the same jsp page

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm doing a project using JSP and Struts. I have a JSP page in which a textbox and a button is there. On entering the ID on the textbox and on clicking the button, all the details of that ID will be displayed on the same page along with an update button. but when the user change the value in the textbox and on the click of update button, Iam not able to retrieve those changed values of textbox and to update the database table. Can anybody please help me.
Thanking You....
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show any code?
The HTML form would be useful as well as the endpoint on the server it hits.
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the click of search button, every details of that particular id is visible on the specific textboxes in the same page and user can change the values. But i dont know how to retrieve those changed values and to update the table.
 
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're performing too much logic in your JSP. All of this logic should be in a Servlet instead.
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What should I do if I want to display or enable the textboxes with valid values only when user types the correct ID and click on search button on the same JSP Page. What is the code to write in servlet if I want to enable textboxes only after entering or submitting the correct ID and to do update.
 
Stephan van Hulst
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The search should be handled by a Servlet, which (AFTER it has interacted with the database, and performed additional processing) can do one of two things:

1) If the request is an AJAX request, simply return the relevant search information in JSON format.
2) If it isn't, forward the search information to the JSP. The JSP code should only display information it receives from the Servlet, and not perform any logic by itself.
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir,
Can you please explain how to implement this... Actually I tried but Iam not able to do it... Please explain....
Thanking You.....
 
Stephan van Hulst
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Create a method in a Servlet to handle the search.
2) Process the request, interact with DB, etc.
3) Create an object containing all data you want to display. This is called a view model.
4) Add the view model to the request, and forward it to the JSP.
5) Display the data in the view model. No more processing should be done here.

If you're stuck with any of these steps, show us what you've tried so far, and tell us what you're stuck on.

Don't do too much in one go. First try forwarding some simple data to the JSP, and display only that. Then expand what you have in steps.
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have given search code inside a servlet and I set each values using setAttribute() method. In JSP page i have used request.getAttribute() to display the value but it is showing null. I have tried the same in struts action class then also the same result. I want to do search and update should be in the same jsp page..... On the click of search I want to display the values in the text boxes and on the click of update , update should work.. Can you show me an example as Iam new to this, I'm not able to work correctly...

Thanking You....
 
Sheriff
Posts: 67746
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
Please read this article for an explanation of how to structure Java web apps.
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Sir...
Iam not able to understand that....
how will I call the object of a class inside servlet or struts action class in a jsp page to display the value....
Please help me....
 
Zeona Neo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried but not working. I have created object of the class and added every data to the object but on the click search button nothing is coming just the page get refreshed.
 
Stephan van Hulst
Saloon Keeper
Posts: 15489
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you're performing a redirect instead of a forward. Can you show us your Servlet code?
reply
    Bookmark Topic Watch Topic
  • New Topic