Wednesday, 25 July 2012

More struts-config.xml file in your Project

Is it possible to have multiple struts-config.xml in a single project ?

Answer:- YES

Yes,  its a new flavor for developers. In today's it is one of the most FAQ from most of the prominent IT/Software companies.

Yes, it is not too hard to implement struts-config.xml file more than one in your project. But , it may hazardous in case of proper settings.


Basically as per my experience multiple number of struts-config.xml file is not required always but in few cases when the project flow has many modules/sections and the development team want to maintain a separation layer for all module including struts fetures at that time we may require it.Here is the easy steps you can follow :-

Steps to Follow :-


 First few changes in WEB-INF/web.xml












Now, create 2 ( any number of xml file you can do) xml file as mentioned inside the web.xml file.
struts-config.xml 
struts-extra-config.xml
  

 struts-config.xml 

 










struts-extra-config.xml ( This is 2nd struts config file)










Now create 2 action file (Action Servlet) as per our example :-

MainactionAction.java
ExtrastrutsfileAction.java


MainactionAction.java














ExtrastrutsfileAction.java 














Finally create 3 jsp file for mapping forword .

index.jsp
main_struts_config_jsp.jsp
extra_struts_config_jsp.jsp

index.jsp


This file is first file from which we will send request to action.














Now your project structure like below :- 



Now run your project & Enjoy your multiple struts-config.xml file in a single project . Any doubt ping me.



Tuesday, 24 July 2012

Find a sub string from as string splited by delimiter in MYSQL

String operation with MYSQL database is quite simple. But some times it found very ridiculous to find a expected result.That exactly happens with me. Actually I was expecting the result like below :-





But when I run my query it generates the out put like below:-




But i want only the name before the first comma(,) occurrence like :-

 Jon kumar Pattnaik from first row.

To find the expected result from database I have used SUBSTRING_INDEX(str,delim,index count) method.A string operation method .

Query :-

select SUBSTRING_INDEX(GROUP_CONCAT(s.vchSName,' ',vchMidName,' ',vchLastName),',',1) as nam,vchSGudian,vchSGRelation  from t_emp_details ;


Now its running fine with a good expected result.



SUBSTRING_INDEX(str,delim,index count)

Notes :- Parameters

str- is the main string from which we need to find the substring.
delim- is the separator of main string.
index count- is the number of separator you want to find.

Example:-
You,are,a,programmer.

select SUBSTRING_INDEX( 'You,are,a,programmer',',',1) from myTable;

Out put:- You

Here in the above query :-

You,are,a,programmer.--( Main String)
comma (,) -- (Separator or delim)
1 --(Index Count)