• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static methods in Servlet

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Are the methods of the HttpServlet like doGet , doPost ---- are static by default ??

I refered to the API but could not find any thing related to static .
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No those methods are not static. However, assuming this question is for an assignment, you might want to think through how a static method behaves and how simmilar (or otherwise) that behaviour might be to how a Servlet works.
 
avi sinha
Ranch Hand
Posts: 453
Google Web Toolkit Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:Hi

Are the methods of the HttpServlet like doGet , doPost ---- are static by default ??

I refered to the API but could not find any thing related to static .


no they are not static.
their signature is

avi sinha
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then can you please tell me why this error is coming .
I have written a Controller class for getting access to EntityManagerFactory .


Inside my Servlet doGet i am trying to create EntityMnaagerFactory



Cannot Make a reference to the non static method getEMF from the type Controller
 
Aditya Keyal
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cannot Make a reference to the non static method getEMF from the type Controller



This has absolutely nothing to do with doGet or doPost being static. Your method getEMF is supposed non-static but you are accessing it in a static fashion. So either

a) Add a static keyword to the getEMF method
--- OR ---
b) Create an object of Controller and then call getEMF from the object.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it .Thanks .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic