Skip to main content

Posts

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 ...