• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions regarding servlet context and methods

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 214
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic