Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating values for form input elements using servlet

 
Dilip Ganesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I needs to populate values for listboxes , textboxes .. almost all the form input elements from my servlet . Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

Is there anyway for setting all the Input Element values from the servlet itself? For example if i needs to set the value for textfield , then in my servlet



In my jsp page

or using any tag library also fine.

How can we achieve this type of functionality or any framework is available? Please help me.

Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilip Ganesh wrote: Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?
 
Dilip Ganesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Dilip Ganesh wrote: Because sending the object to the JSP page and populating the values for the input elements there (using any tag libraries JSTL) i found it difficult.

It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?


Thank you so much for your quick reply. In my servlet i am calling web services to fetch the data's. So i will get the data in xml format. For example if i wants to create a new person , in that page i will show the fields like Country , State all this fields values are coming from webservices only. So sending this XML values to JSP and parsing there i found some what difficult. If i am using JAXB also same , i needs to send the JAXBObject to my jsp page and i need to populate values there. I hope it is clear.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should do all the XML parsing in the servlet, capture the data in normal Java objects, and send those to the JSP. In the JSP, the EL and JSTL can be easily used to consume this data.

The best way to always approach this is to make the servlet do all the hard work of massaging the data into a structure that makes it easy for the JSP to do its job. In other words, keep the JSPs as stupid as possible.
 
vinayak jog
Ranch Hand
Posts: 83
MySQL Database Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault is right. It disturbs MVC architecture if you put too much code in JSP. JSP should be view component
 
Dilip Ganesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for your suggestions
 
Dilip Ganesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should not be difficult. So instead of trying to find some other weird way of doing it -- which is most likely to be even more difficult because it's not natural -- makes no sense at all.

The best approach would be to try to find out what you are doing wrong that makes it difficult.

So what difficulties did you run into?


I agree to your approach. Just wants to share with you in gridsphere portal we can set the form element values from the portlet itself.

i.e Gridsphere portal having their own Custom Tag Library , so that we can access those tag library classes inside the portlet class and we can set the values for those .

So i wants to know whether it is possible in servlets or not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic