Posts

Showing posts with the label netbean

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();   ...

RESTful WS using Jersey Part 1 - Hello World

Image
Here is the simple tutorial for RESTful Web Service using jersey implementation for RESTful Web Services. Java EE 6 has introduced jersey API as implementation for JSR-311 as API for RESTful Web Services. For ease of development,deployment and testing i have used NetBean 6.8 which supports JEE 6. Jersey is an annotation based implementation. Here are the few important annotations used in this tutorial @path(“/path/”) - a relative URI path indicating where the Java class will be hosted @GET - a request method designator and corresponds to HTTP Get method @POST - a request method designator and corresponds to HTTP Post method @Produces("text/plain") - specify the MIME media types of representations a resource can produce @Consumes("text/plain") -specify the MIME media types of representations a resource can consume @PathParam("User_Name") - a type of parameter that you can extract for use in your resource class @QueryPar...