Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions regarding servlet context and methods  RSS feed

 
karthik ekantha
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doubts:


1)can we create object for servletContext?
2)ServletContext context= ---------getServletcontext------------->here nothing request not there ? why?something request.getServletcontext.
3)how to pass the query in the URL in servlets?
4)doGet & doPost & service difference? all the method separately working in the particular servlet.then wt is diff ?
5)how to overrride the doget& dopost method give basic example?
 
D. Ogranos
Ranch Hand
Posts: 214
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Not sure what you mean here. Create an object and put it into the ServletContext? That can be done with getServletContext().setAttribute("name", object). If you meant "how do I create a ServletContext object", you don't. The servlet container does that for you.

2) Again, not sure what you mean. The method getServletContext() is provided by GenericServlet, from which HttpServlet inherits. Check the API for GenericServlet.

3) That's not something YOU do. The servlet container maps incoming requests to the appropriate servlet, and provides the request parameters through the HttpServletRequest object (which is a parameter of the doGet() and doPost() methods).

4) doGet() is called for HTML GET requests, doPost() for HTML POST requests. A request can only have one of these so its always clear which servlet method will be called.

5) You override them like any other method, by providing an implementation for them.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future, please be sure to take the time to compose descriptive subjects for your posts. You will attract people who will can give you better and faster answers when your posts have good, descriptive subjects. For more information, please click this link ⇒ UseAMeaningfulSubjectLine.

I have adjusted the title of this topic for you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!