Skip to main content

Posts

Showing posts from 2012

Creating a Struts-2 hello world application on eclipse

Hi, This is a getting started tutorial for struts-2. Struts-2 is similar to struts-1 but there are certain changes in terms of functionality and syntax. The main components needed to create the demo application are as follows: 1. Eclipse indigo. 2. Struts-2 distribution:- To download struts-2 distribution go to 'http://struts.apache.org/download.cgi#struts238-SNAPSHOT' and download 'Full Distribution: struts-2.3.7-all.zip (76mb) [ PGP ] [ MD5 ] ' 3. Tomcat 7. That is all you need to create a struts application. Application Structure: The demo application that we are going to create using struts-2 is a login application. The application will be having following components: 1. index.jsp 2. HelloWorld.jsp 3. error.jsp 4. HelloWorldAction.java Now the application proceeds as follows: 1. When the application starts the user is presented with 'index.jsp' where the user enters username and password. 2. On submitting the 'index.jsp' page

Uploading a binary file to RESTful web service in java using Jersey

Hi, Recently I had a situation where I was supposed to upload a binary file to a server side RESTful web service created in Jersey. I faced a lot of trouble in doing so because always one or the other part of the hood was not working properly. The following post gives a step by step process as how to create a RESTful service that accepts uploaded binary files. Pre-requisites: 1. A running RESTful service based on Jersey. 2. An HTML page with file upload component. 3. Tomcat 7 as web server. 4. Eclipse indigo. Note: Let us suppose that tomcat is running on same machine on which the HTML client is present. So we will be using the base domain URL as ' http://localhost:8080/ '. If your service and client are located on different instances of tomcat then replace the localhost part of the URL with the IP address of the machine on which the REST service is running. Step 1 (Eclipse setup): a. Create a 'Dynamic Web Project' in eclipse indigo. Let us say that thi

Parsing an XML document using SAX Parser in Java

This is again a "getting started tutorial" of how to start using XML parsing concepts in java. For further details of using XML parsing please refer tutorials at : http://docs.oracle.com/javase/tutorial/jaxp/sax/index.html . The program presented here is a simple demonstration of how to parse an XML document using SAX-XML parser for java. For demonstration purpose a sample .xml file is also included. temp.xml : <?xml version="1.0"?> <company>     <staff department="information security">         <firstname>FIRST NAME-1</firstname>         <lastname>LAST NAME-1</lastname>         <nickname>STUDENT-1</nickname>         <salary>100000</salary>     </staff>     <staff>         <firstname>FIRST NAME-2</firstname>         <lastname>LAST NAME-2</lastname>         <nickname>STUDENT-2</nickname>         <salary>200000</salary