Skip to main content

Posts

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