• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Access jstl variable in Servlet

 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im populating customer data by iterating a customer list as following in the jsp.



Now in the action either edit or delete each record i want to track which customer needs to be edit/delete. So in servlet how can i access the customer object which is in var listItems. If its not possible do i need to have hidden input variables with values and access them using getParameter in servlet?
 
Sheriff
Posts: 67750
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
Yes, only form elements are submitted as part of a form.

Remember that once the response leaves the server that it's just an HTML page. So there's no way that a JSTL value (or any other server-side value) can be submitted with a form that only exists on the client.

Please read this article to understand how JSP operates.
 
Harshana Dias
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Yes, only form elements are submitted as part of a form.



Yes but defining hidden input variable does not gives a solution for identify which customer detail like fname to either edit or delete that record. Because it will eventually have a list of hidden input variables with same name and different values.
 
Bear Bibeault
Sheriff
Posts: 67750
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
How is the user choosing which of the displayed items is to be submitted?
 
Harshana Dias
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:How is the user choosing which of the displayed items is to be submitted?



Thank you for the answer. Its like a data grid where each customer records are displayed with edit/delete button next to it. So once the user click on delete for example that cutomer information should be delete. So for that need to send the fname for the servlet to process know. That's where i need to know how to track it.
 
Bear Bibeault
Sheriff
Posts: 67750
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
fname? What's that? Is it the primary key for the database record?

In any case, you need to send the primary key for the record to identify which one was chosen.

This is not a JSP issue, it's an HTML issue. How would you construct the HTML, and perhaps JavaScript, of this page to be able to submit the primary key of the record?

Once you've answered that question, then what you need to do in the JSP becomes clear.
 
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also got this kind of problem few days back I can tell you what I did.
Instead of using 2 buttons for edit and delete, I used 2 link like this-

<a href="welcomeC.do?mode=e&img=${LoginCBean.image}">Edit</a>

here you can send your primary key and variable(here it is mode) which tells servlet that edit is clicked or delete and you will be able to do coding according to that variable.
 
Bear Bibeault
Sheriff
Posts: 67750
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
I would not recommend this approach. Links are a poor substitute for buttons in a UI.

I'm still waiting for answers to my questions before I can make any recommendations.
 
Harshana Dias
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I'm still waiting for answers to my questions before I can make any recommendations.



Yes Bear Your right. Using javascript i have set the action clicked customers primary key to a hidden variable.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic