• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why driver and url passed as context params

 
abhishek_saxena
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wanna know why driver name and url passed as context params in a generic Servlet why not init params and can we write the business logic statements in INIT Method rather than service do we get the same output
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servletContext contains data common to all your servlet application.
Typically an application will use one database and thus the settings to access it are the same for the servlets.

On the contrary the init parameters are specific to one servlet.
You will find data specific to the use case served by the servlet.

hope it will help
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by abs saxena:
i wanna know why driver name and url passed as context params in a generic Servlet why not init params and can we write the business logic statements in INIT Method rather than service do we get the same output


Hi "abs saxena",

Welcome to JavaRanch . The context param is for the entire web applciation and init param is for individual servlets.

As ntumba lobo mentioned, we do maintain ONE database/datasource for an application in general. That's the reason they are mentioned in the generic Context Param. Moreover, if at all you have to change the parameters, you can easily change it at one place.

Hope this helps!
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "abs saxena",

Not very sure your first name "abs" has some REAL meaning. If not I would suggest you to kindly look at the Naming Policy of JavaRanch and you can easily convert/change your name by editing your profile
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic