Can we define Constructors in servlets and if we can then
how can we call it?
one more thing is can we define methods in Jsp file..
You can define methods in JSP, the same way as u declare variables.
Probably you don't need that. Why do you want to do this?
If you want to define a constructor in a servlet, you can only define a no-parameter constructor. In general, most developers don't do this. Typically, they put construction-type logic in the servlet's init() method instead.
You can't define constructors for your servlet since the servlets are initialized by the container. Would give you compilation error.
One can definitely have constructor in servlet.Even you can user the constrctor in servlet for initialization purpose,but this type of approch is not so common.You can perform common operations with the constructor as you normally do.The only thing is that you cannot call that constructor explicitly by the new keyword as we normally do.In the case of servlet, servlet container is responsible for instentiating the servlet, so the constructor is also called by servlet container only.