Essential Knowledge on Web Component Development #Java Short Notes

  • doGet() processes HEAD requests in the absence of a doHead() method
  • Not the service() method but the methods that are called by the service method are better candidates for overriding
  • HttpServlet supports GET, POST, DELETE, OPTIONS, and TRACE requests
  • Retrieve a single value for a form parameter named “username”: String u = request.getParameter(“username”);, String u = request.getParameterValues(“username”)[0];
  • java.util.Enumeration getHeaderNames() – retrieves the complete collection of request headers
  • set the content type of a servlet response:
    response.setContentType(“text/html”);
    response.setHeader(“Content-Type”, “text/html”);
    response.addHeader(“Content-Type”, “text/html”);
  • Servlet.destroy(): Servlets release resources: When called, the servlet container may not route other requests to that instance of the servlet: Servlet.destroy() may never be called
  • The destroy() method, called by the web container when the servlet (or the web application) is being shutdown. This is a very good place to put the code to close related socket connection
  • no guarantee on when the finalize() method will be called by the JVM
  • The init() method is called by the web container before any HTTP requests are processed by the servlet. This is a good place to open a socket connection
  • web.xml, JAR files, Class files, the deployment descriptor – are expected to be placed under WEB-INF directory
  • A welcome file: used when a user requests a directory
  • welcome files may be used at any directory level
  • the default servlet is used to handle requests for specific files that exist in the webapp
  • By default, the web container sends a 404 error back if the requested file does not exist
  • Define a mime-mapping:pdfapplication/pdf
  • WAR files are created using the jar command.
  • A web application may be packaged into a WAR file for deployment, but it is not required.
  • The files within the WEB-INF directory and the files within the META-INF directory of a WAR file must not be directly served as content by the container in response to a Web client’s request.
  • A webapp can only have one web.xml file and all configuration must exist in that one file even if the Java class files exist in some other package
  • String boundObjectName = getServletContext().getInitParameter(“com.example.BoundObj”);:returns a String if an initializathttp://www.justetc.net/knowledge/editArticlesNext.phphttp://www.justetc.net/knowledge/editArticlesNext.phpion parameter of that name exists in web.xml
  • session.removeAttribute(“app.util.DataSource”);: removes a session attribute
  • Servlet context listeners are notified when the context is ready to process requests and when it is about to be shut down
  • HttpSession.setAttribute(String attributeName,Object value): method stores an object

From: http://sitestree.com/?p=4929
Categories:Java Short Notes
Tags:
Post Data:2008-09-09 09:45:43

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada