Posts

Showing posts with the label servlet

XML Oriented vs Annotation oriented programming

What is XML Oriented programming ? – In this approach every application have one or set of documents associated with it. This xml documents contain application configuration information which are defines application’s run time behavior. It is very easy to maintain frequently changing configurations setting using xml document. What is Annotation Oriented Programming ? – Annotation oriented programming language leverage active code generation with the use of declaration tags embedded within the application source code to generate any other kind of source code, configuration files etc. XML vs Annotation 1. XML duplicates a lot of information like class, method name etc. But annotation are part of class it self so no duplication of information. For example web.xml <servlet> <servlet-name> DemoServlet </servlet-name> <servlet-class> demo.servlet.DemoServlet </servlet-class> </servlet> <servlet-map...

Downloading a file from web application

Image
      This post explains developing a web application which allows requestor to download a file. Here web app will have a servlet which streams requested file to requestor. follow the step to develop it using NetBean 6.8 1. Create a web application [ refer previous posts ] 2.Create a Servlet and add the code given below in doGet method      String filePath =null;      int length =0;        //accept file name as parameter         String fileName = request.getParameter("FILE_NAME");         InputStream is = getServletContext().getClassLoader().getResourceAsStream("/"+fileName);         if(is == null){             PrintWriter writer = response.getWriter();   ...

First hand on Servlet 3.0 using Annotation

Image
   This tutorial gives introduction to coding and deploying Servlet as per 3.0 specification. Servlet 3.0 specification introduced Annotations that makes deploying servlet, Lister and Filter easier ever before. Here is the Servlet with Annotation ready to deploy without any web.xml. Here @webservlet annotation is being used to define servlet name, url pattern and init parameters. This annatation is equivalent to following entry in web.xml < servlet > <servlet-name> HelloServlet </servlet-name> <servlet-class> demo.HelloServlet </servlet-class> <init-param> <param-name> name </param-name> <param-value> Yogesh </param-value> </init-param> </servlet> < servlet-mapping > <servlet-name> HelloServlet </servlet-name> <url-pattern> /HelloServlet </url-pattern> </servlet-mapping> Complete Code : /* * To change this tem...