Posts

How decorator pattern works

Image
Decorator is a structural pattern that adds additional responsibility to the object at run time. This pattern adds responsibility to a particular object not on the class. As a result different object of same type can have different responsibilities. I would explain a real life example from my experience. I am a biker. Every morning I go to office riding on my bike. When I bought this bike the seller just sold the standard bike to me. They didn't provide any tail light, head light, mud guard and even the kickstand with the bike. Later I added or decorated my bike by adding a tail light, mud guard and with a kickstand. So, functionality of each of this component is different. I added them with my bike and they are responsible for additional functionalities. This can be thought of as a decorator pattern example. Here first I have the bike with standard installation. Then I decorated it with other component. Participants in a decorator pattern are Component interface a Conc

How to query for tweets using twitter4j

Twitter has killed their API 1.0 on June 11, 2013. Now you cannot do a search query without authentication. Twitter4j is an excellent library for java developers to implement twitter things. You can update status, get a timeline, query for tweets using this library. Here I am going to show you how to query using twitter4j library Twitter twitter = new TwitterFactory().getInstance(); AccessToken accessToken = new AccessToken("You-Access-Token-Key", "Your-Access-Token-Secret-Key"); twitter.setOAuthConsumer("Your-Consumer-Token-Key", "Your-Consumer-Token-Secret-Key"); twitter.setOAuthAccessToken(accessToken); try { Query query = new Query("#Shahbag"); QueryResult result; result = twitter.search(query); List tweets = result.getTweets(); for (Status tweet : tweets) { System.out.println("@" + tweet.getUser().getScreenNam

Oracle Export, Import using sqlplus

Image
I will write here about oracle export,import using sqlplus. I assumed that you have basic idea about oracle, sql. There may situation like follows:- You want to copy some tables from one schema to another schema You want to copy a schema into another database You want to copy table rows from one schema to another schema You can do this using oracle export, import facilities. These two facilities are really powerful to smooth data transfer. Usually I do this using sqlplus command facilities. ExportProcess : At first you need to create dump file. Enter command prompt then type exp in the prompt. It will ask for userid and password of the schema. Suppose your schema is ab and listener name is biis and password is ab . Then type mak@iis and then password makiis. Then choose the dump file location. You may choose default directory by just entering file name or choose any other location say c:\\ab.dmp. The dump file will be stored in C drive. There are some dump options tha

Custom Request Processor in Struts

I assume that you know the basics of struts and you are using lower version than that of struts 2.0. Struts is a powerful MVC framework which can be extended to do some excellent work. There may be situations where you need some regular works at every actions. Such as validating the user, checking his/her roles, log user activities etc. Struts provides a way for that. ActionServlet is the only servlet in Struts. Before redirecting to the programmer's action, ActionServlet creates an object of RequestProcessor. The RequestProcessor class in the Struts distribution provides a default implementation for each of the request-processing steps. That means you can override only the methods that interest you, and use default implementations for rest of the methods. The processPreprocess method in RequestProcessor can be overridden to do some common tasks such as 1. Validating User Session 2. Validating User Role 3. Putting Action Form's Data Into User Log Table. You have to do

Preventing Duplicate Form Submission in Struts using TOKEN

Duplicate form submission may occur in the following situations:- Using Refresh button Using the browser back button to traverse back and resubmit form Using Browser history feature and re-submit form. Malicious submissions to adversely impact the server or personal gains Clicking more than once on a transaction that take longer than usual What happens in form submission? Suppose you have a form named adduser.jsp and an Action named saveUser.do. So, on clicking submit in the adduser.jsp page struts finds the mapping saveUser.do and redirect to this url. So, in the browser url you will find /app/saveUser.do. and when you click on refresh same url is called and same form is submitted again. Struts provides several ways to protect this. HTTP redirect after form submission using TOKEN HTTP redirect Suppose form submission result is shown in a page called success.jsp. So, if redirect is set true in forward of action in struts.config URL in the URL bar becomes /app/success.j

jQuery Autocomplete

Autocomplete using jQuery is quite easy. jQuery made this cumbersome work easy for programmers. So what is needed for autocomplete feature in your page jquery.js jquery.autocomplete.js jquery.autocomplete.css file Just include these three files in header. Ad the following script to your header function showItem(row) { return row[0]; } $(document).ready(function() { $("#category").autocomplete( "getcategory.php", { minChars:1, max: 200, scrollHeight: 180, formatItem:showItem } ); }); Let us depicts about the above code segments. Here #category means the category id on which you want autocomplete feature. and "getcategory.php" is the server side file which will provide result for autocomplete. Now let us discuss about the parameters. minChars : minimum character in the input to call autocomplete max: maximum item in the list. No more items exceeding this value will not be displayed. Its default value is 10 scrollHeight: this

Various Web Layouts (Fixed, Elastic, Liquid)

Web designers basically have three layouts based on CSS. They are :- 1. Fixed 2. Elastic 3. Liquid All of the above has its own advantages and disadvantages. I will describe here details of these three. 1. Fixed Layout Fixed layout websites looks same in all container. Whatever the monitor size, pixel it is always same. Because of its rigidity it is also called ice layout. Developer can organize elements any way he/she likes. If you set the width of your design to be 720 pixels wide, it will always be 720 pixels. If you then want a branding image spanning the top of your design, you know it needs to be 720 pixels wide to fit. Disadvantages. This layout cannot utilize space available. They are always same what ever the window size is. A site made for 800 600 screen resolution looks tiny in a higher resolution screen and in vice versa a site made for 1024 760 screen will cause scrolling in lower resolution. A reader with a mobile phone or a handheld computer will have to