• Post Reply Bookmark Topic Watch Topic
  • New Topic

any way in servlet for preloading the data in my first page  RSS feed

 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i have index.jsp

which contains the select box called country
i have the country details in jsp

before loading the index.jsp the values should be fetched from the DB and that value should be listed in the index.jsp

i dont want to call a javascript on body on load

is there any way we can do this functionality using servlets or listeners

 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Afterall the user will be served some HTML (select box in this case) , so you have to generate the select box dynamically (since the values getting from the DB). So you should use DOM objects for that.
 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean to say i should implement the business logic from the jsp itself
cant i have my busineess logic seperated from jsp
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasanna RamKumar wrote:you mean to say i should implement the business logic from the jsp itself

No.
cant i have my busineess logic seperated from jsp

Yes. Business logic should be separated from the JSP.

When you create select box dynamically you should manipulate the HTML elements using DOM.


 
Prasanna RamKumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are not getting the point
select box will be generated from the DOM object only

for the value i will have an arraylist right

i want to fetch the values (country list) before loading my jsp page which will be shown to the user

if iam using the servlet to fetch the values first how can i call the servlet first

should i use any listeners to call the servlet

so that it will first fetch values and set in request attribute so that i can get the attribute in my request scope of jsp





 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasanna RamKumar wrote:if iam using the servlet to fetch the values first how can i call the servlet first. should i use any listeners to call the servlet. So that it will first fetch values and set in request attribute so that i can get the attribute in my request scope of jsp


Use a URL mapping to the servlet for that specific request from the user then in the servlet you can set the List (or what ever) in the request scope and forward the request to the appropriate jsp.
 
Fidel Edwards
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As Far As I am understanding,You should put your collection(say arraylist) of country in session before the page loads ,and then just fetch and iterate that session value in your select box .

I think you are getting my point In case of any problem please let me know .

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the values don't change over the life-cycle of the application, you can use a Context Listener that will execute once at application startup, and store the values in application context where they will be available for the life of the application.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!