Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access jstl variable in Servlet

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 333
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the user choosing which of the displayed items is to be submitted?
 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
ronney singh
Ranch Hand
Posts: 40
IBM DB2 Java
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 333
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic