Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet init parameters

 
robert dodson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


"A servlet init parameter cannot have the same name with the servlet it refers to"

I think this is wrong but I dont know where to find out for sure and why its wrong. I think I read it somewhere but I can not find it can anyone explain this to a noob
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it isn't in the Servlet Spec, it's not real.
 
robert dodson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the fast response
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. With all things servlets, the Spec has the final word.

You could also just try it and see what happens!
 
Swetha Bhagavathula
Ranch Hand
Posts: 112
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
robert dodson wrote:

"A servlet init parameter cannot have the same name with the servlet it refers to"

I think this is wrong but I dont know where to find out for sure and why its wrong. I think I read it somewhere but I can not find it can anyone explain this to a noob

Hai.. do you mean the life cycle method:public void init(ServletConfig servletconfig){//code}

if so then;please see this:

public void init(ServletConfig servletconfig){
this.config=config;
init();}


the above is the one of the life cycle methods of servlet..(the three life cycle methods of servlet:init(ServletConfig),service(ServletRequest,ServletResponse),destroy() )

a servlet interface contains this as a abstract method and GenericServlet(abstract class) implementing the " javax.servlet.Servlet(interface),javax.servlet.ServletConfig(interface), java.io.Serializable (marker interface)"contains this method.
init(-) method is the lifecycle method of servlet program which is executed by servlet container for instantiation event having ServletConfig object as argument value on our servlet class.since a good programmer will execute keeps his intialization logic of servlet program by overriding " init()" method and gives chance to inti(-) of GenericServlet class to execute.
the init(-) apart from performing initialization process ,invokes init() method at the end.
ServletCnfig object is the right hand(useful) object for our servlet program.It is one per servlet object.To pass information to servlet program ,we can use this ServletConfig object.Servlet container creates this
ServletConfig object when instantiation event is raised on our servlet class.
ServletConfig object means,it is the object of servlet container supplied java class that implements "javax.servlet.ServletConfig " interface.using this servletconfig bject when can get various details of our servlet program.our class(user defined class) extends HttpServlet class which is an abstract class that inturns extends GenericServlet class.
ex: public class servletdemo extends HttpServlet{//code}.As we cannot create object to HttpServlet class since abstract class we make our class extends it and use the required methods like doXxx(-,-) /service(-,-).
The beauty of HttpServlet class is, it an abstract class that contains no abstract methods(as any abstract class may or may not contain abstract method,means it can contain abstract methods also concrete methods)

for better understanding i suggest you to refer the source code of servlet-api. If you find the above explanation is not help full then please excuse me.. Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, he was asking about servlet init parameters, not the init() life-cycle method.
 
Swetha Bhagavathula
Ranch Hand
Posts: 112
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
robert dodson wrote:

"A servlet init parameter cannot have the same name with the servlet it refers to"

I think this is wrong but I dont know where to find out for sure and why its wrong. I think I read it somewhere but I can not find it can anyone explain this to a noob

hi..
you can happily use same logical name for servlet as well as parameter name of your init-parameter.It is allowed because your<servlet-name> is the logical name used by the container during instatiation event.. object creation for you servlet class .. where as ini-parameter is used for a specific servlet to configure driver class names db url,dbpwd etc such parameter names.so these both are no where related .. note that init-parameter can have any value the paramter name of servlet program..same thing applies to context-parameter also.Hence,the statement is false.. A servlet iniit-parameter can have the same name with the servlet it refers to.. (this is true).

ex:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic