Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .

 
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
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic