• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 244
  • 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: 67753
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.
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic