Skip to main content

Posts

Struts 2.1.2 Released

Yesterday when I was searching for something on Google. I found that Apache had released the latest version of Struts 2 which is Struts 2.1.2 , and promoted it to Beta on 26 March 2008 Struts 2 in Action You can download it from Struts Download Page

Struts 2 Hello World Example

I had seen many new deveopers struggling against struts2 hello world example. So I decided to write a small example. Below are the required libraries to run this example which are easily availabel struts2-core-2.1.8.1 xwork-core-2.1.6 commons-logging-1.0.4 commons-logging-api-1.1 freemarker-2.3.8 ognl-2.7.3 commons-fileupload-1.2 The structure of the applictaion which I am following is (Eclipse IDE) Struts2Demo |---src | |----org | | |----vinod | | | |----action | | | | |----HelloWorld।java |---struts.xml |---WebContent | |---jsp | |---HelloWorld।jsp |---index.jsp |---WEB-INF | |---lib | |---web.xml Struts 2 in Action It is true that different IDE's use different structure, but at last when war is build they follow same structure. Lets start... HelloWorld.java import com.opensymphony.xwork2.ActionSupport; public class HelloWorld extends ActionSupport { String greetings = null; public String execute() throws Exception { setGreetings("Hel

Java Code Names

Yesterday I was crawling web and found some intersting things about java. Firstly when java was release its name is Oak. After some time the creator of java found the name Java . I found some of the intersting things like the code names of the reeases of the java which I am going to describe below. VERSION CODE NAME RELEASE DATE Version Description of Code Name Code Name Date of Release JDK 1.1.4 Sparkler Sept 12, 1997 JDK 1.1.5 Pumpkin Dec 3, 1997 JDK 1.1.6 A female character in Bible Abigail April 24, 1998 JDK 1.1.7 Roman cognomen used by several politicians Brutus Sept 28, 1998 JDK 1.1.8 Name of a person/Football club Chelsea April 8, 1999 J2SE 1.2 Playground Playground Dec 4, 1998 J2SE 1.2.1 (none) March 30, 1999 J2SE 1.2.2 Cricket July 8, 1999 J2SE 1.3 Kestrel May 8, 2000 J2SE 1.3.1 Ladybird May 17, 2001 J2SE 1.4.0 Merlin Feb 13, 2002 J2SE 1.4.1 Hopper Sept 16, 2002 J2SE 1.4.2 Mantis June 26, 2003 J2SE 5.0 (1.5.0) Tiger Sept 29, 2004 Java SE 6 Mustang Java SE 7 Dolphin You

Deadly Combination

Yes, Deadly combination!! It doesn't means that there would some super stars of the film who would go the devil place and finish him. No No !! I am talking about the deadly combination used in the development of the web sites. I am talking about the tools used for the Java development. Any guesses so far.... Yes, they are Struts2 , Spring , and Hibernate I am currently working all these tools. I am amazed to see the power of all the three technologies and how they makes the life of a developer like me, so easy. All of three would make your project a huge success. Now talking about Struts2 ... It is great framework with the inbuilt Ajax tags that would help many developers. Many new features of the struts2 are marvelous. Hibernate ... I already told in my last post about this. Hibernate would provide you a greater facility for your data persistence. its in built architecture that is fully object oriented which makes it a powerful tool. And yes, not to forget about the HQL (Hi

Hibernate Rocks

After few days working on hibernate I found it very interesting and useful tool for the developers. It allows to handle code more efficiently while working on the database part. Since I am new to it I don't know all the features of the hibernate, but yes the features that I had used are tremendous and the code is more reliable and efficient. All the connection management is handled by it. And specially the mapping files which allows us to connect to the database I enjoyed working with it and hopes it will provide more features in the future.

Changing default style of <s:actionerror/> / <s:actionmessage/> tag

In struts 2 when you put <s:actionerror /> tag it displays the errors in the following way: <ul> <li>error 1</li> <li>error 2</li> </ul> But sometimes it seems to be very ugly when displaying the dot (.) in the action errors or action messages Below is a normal code that displays the tags in your customized way. You can specify your own css for this <s:if test="hasActionErrors()"> <s:iterator value="actionErrors"> <span class="errorMessage"><s:property escape="false" /> </span> </s:iterator> </s:if> Alternatively you can change the file in the "/template/simple/actionerror.ftl” and put it in the /web-directory/struts/simple if using simple theme Similar for <s:actionmessage /> tag. Enjoy Struts

Session Check Interceptor

There must be some way to check that the current session is valid or invalid. This can be done using interceptors in struts in a very easy way. Here I am giving an example how to resolve this. First of all we will make an interceptor named SessionCheck.java. package com.demo.interceptors; import java.util.Collections; import java.util.Map; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionProxy; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.interceptor.Interceptor; public class SessionCheck implements Interceptor { public void init() { } public void destroy() { } public String intercept(ActionInvocation invocation) throws Exception { ActionProxy proxy; proxy = invocation.getProxy(); Map session = ActionContext.getContext().getSession(); Map results = proxy.getConfig().getResults(); // We are checking that the user that is set at logi