Skip to main content

Posts

Showing posts from June, 2008

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

Struts 2 Ajax drop down Example

Struts 2 has emerged as boon for developers. But the documentation available is very small. So I had decided to give a brief demonstration of the ajax used in struts 2.1.8.1 Libraries used: commons-beanutils-1.7.0.jar commons-fileupload-1.2.jar commons-logging-1.1.jar commons-logging-api-1.1.jar freemarker-2.3.8.jar struts2-core-2.1.8.1.jar struts2-dojo-plugin-2.1.8.1.jar xwork-core-2.1.6.jar In this example when u select from one drop down the other will populate accordingly. You can use it as it is or play with it. Enjoy !! index.jsp <%@ taglib prefix="s" uri="/struts-tags" %> <s:action name="ListingAction" executeResult="true"></s:action> listing.jsp <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="sx" uri="/struts-dojo-tags"%> Listing detail.jsp <%@ taglib prefix="s" uri="/struts-tags"

Simple LDAP Authentication

This is a simple example through which we will connect to the LDAP Server and authenticate user. I have used ApacheDS Server as a LDAP Server. Install ApacheDS server and run it. Following is a servlet used. make login.html and use as it Login.java package ajaxdemo.action; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; public class Login extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { public Login() { super(); } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String SUCCESS = "Success.html"; final String FAILURE = "Failure.html"; String strUrl = "login.html"; String username = request

Performance Increase

Many of us passes through the same situation of having a low performance of our application. But if you follow some of the tips and tricks below you will soon realize the increase in the performance. Collections Always assign size to ArrayLists and other collections. Ex: Collection c = new ArrayList(10); Strings Always use String abc = "I love Java";instead of String abc = new String("I love Java"); JDBC Always close these statements after use: < Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("databaseUrl","username","password"); Statement stmt = conn.createStatement(); String strSql = "select * from abc"; ResultSet rs = stmt.executeQuery("strSql");// close these stmt.close(); rs.close(); conn.close(); strSql=null; Use only the required columns in select query: Select FIRSTNAME,LASTNAME from PERSON; instead of Select * from Person; JSP

Everywhere Java

Java is everywhere from your shoes to mars and from mobiles to big dream machines and from your favorite bike to space shuttles. You can't even escape Java if you are a programmer or a developer.

Struts2

Struts 2 is a new framework for the java developers. It is a combination of Struts 1 + Webworks formally known as Struts Ti. It is available with the enhanced quality of code and helps developers to work in a more organized way. In built Ajax functionality is a boon for the developers. When I started working on the Struts 2. I felt that it may be very hard to learn but not actually. It is far easier then I thought. I haven’t work on other frameworks like Tapestry, Wicket, Spring etc. but I know what I am doing is good enough for me. All frameworks provide there own way of style of coding which are good in there respect. In built Interceptors provided a great functionality that helps in lots of situations. The one I like is a WaitAndExecute Interceptor. It is very helpful in situations when your action takes lots of time to execute. This interceptor displays a default page when your action is executing at background. Lots of more features are there for developers like Ajax funct