Tuesday, November 18, 2014

How to Include Header and Footer in all Jsp files Dynamically


Include following tag in your web.xml file with your files proper path
it will include Header.jsp in header of all jsp file and Footer.jsp in footer of all the jsp files

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/view/commons/Header.jsp</include-prelude>
<include-coda>/view/commons/Footer.jsp</include-coda>
</jsp-property-group>
</jsp-config>

Sunday, November 16, 2014

STRUTS2 Wildcard Congiguration in struts.xml file

Wildcard configuration in struts.xml file

<action name="*/*"  class="com.raj.rk.controller.{1}.{1}CTRL" method="{2}" >                                     
            <result name="create">/view/{1}/{1}Create.jsp</result>
            <result name="update">/view/{1}/{1}Update.jsp</result>                       
            <result name="view">/view/{1}/{1}View.jsp</result>
            <result name="list">/view/{1}/{1}Search.jsp</result>
</action>

Explanation

name = */*  
If the request comes for action policy/create.action, then the {1} will be policy and {2} will be create. so this both values will be mapped into the respected position in the action tag. and it will work accordingly.

Controller
In this policy/create call the controller called will be PolicyCTRL.java
and the method called will be create() inside the the PolicyCTRL.java class

Result
and the result file called will be /view/policy/PolicyCreate.jsp

Friday, November 7, 2014

FILTER vs INTERCEPTOR

FILTERS
0)  Filter is an Interface
1)  Filters are Java Components. somewhat equivalent to servlet.
2)  Filters intercepts and process the request before it sent to the actual servlet.
- on request object filter can do security checks
- filter can do some log work
- filter can change the request parameter
- filter can reformat the request headers 
- filter can take some decision based on request parameters
3)  Filter intercepts the response received from the servlet before it sent to the end user.
- filter can do some log work for the response
- filter can change the response stream

4)  Filters are configurable in DD (Deployement Descriptor)
5)  Container decides when to invoke which filter
6)  Filters have init(), destroy() and doFilter() methods
7)  One request can be intercepted by multiple filters
8)  Every filter must implemens the Filter Interface
9)  Filter interface is in package "import javax.servlet.Filter;"
10) doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) 
11) As per the declaration of filter in the DD the filter chain will be prepared for the similar url-mapping and servlet-names.
12) The Filter chain concept can also be called a filter stack.

INTERCEPTORS
0)  Interceptor is an Interface
1)  Interceptors are struts2 components similar to Filter
2)  Interceptors intercepts the request before it reach to the servlet and can do the same      
     work as filter can do.
3)  Interceptors intercepts the respons before it reach to the end user and can perform the 
     same work as filter can do.
4)  Interceptors can be declared in the struts specific configuration file (struts.xml)
5)  Interceptors are can be called action specific
6)  Programmer can be define in specific order to create stack of the interceptor. (as filter 
    chaining )
7)  Prepared stack can be used at multiple times for the specified actions
8)  Struts2 provides many useful interceptors (i.e 
     http://struts.apache.org/release/2.3.x/docs/interceptors.html)
9)  To create interceptor we need to implement Interceptor interface
10) Interceptor have three methods void init(),  void destroy() and Strinng 
      intercept(ActionInvocation acIn)
11) package : "import com.opensymphony.xwork2.interceptor.Interceptor;"
12) Interceptor can exclude and include specific method's execution.

I think this is enough basic information about FILTER and INTERCEPTOR :)

KEEP VISITING :) GIVE YOUR RATING AND COMMENTS

Tuesday, October 28, 2014

AJAX call using JQuery

AJAX call using  JQuery 

Example
$.ajax({url:validateUrl,
type: 'POST',
async:false,
data: 'method=validateCondition&condition='+data,
success: function(answerFromServer){
onSuccessValidateCondition(answerFromServer,fieldId);
}
});

Description:
url: URL where the AJAX call will be send.
type: POST , GET etc
async: true/false (Default is True, True will allow other content of the page to load independently of the ajax call. false is reverse of it) 
data: the particular method of the servlet you want to call, and other parameters you can append.
sucess: function(answerFromServer){} : answerFromServer will contains the data sent by server in response of the ajax call

Monday, October 27, 2014

Java Coding Care4 : Avoid Null Pointer Exception

Topic : Avoid Null Pointer Exception

Advantage
Code Execution will be liberal and better. Functionality break chances will be reduced.

Example

1)
if ("check me".equals(param)) // Do like this
{
// some code
}

2)
String str = (param == null) ? "NA" : param;

3)

Use String.valueOf() Rather than toString()

4)
Object object =null;
String.valueOf(object); /// is OK
String.valueOf(null); // throws Exception

Use collections default to get the empty objects of respected data struture
List<String> list = Collections.EMPTY_LIST;
Set<String> set = Collections.EMPTY_SET;
Map<String,String> map = Collections.EMPTY_MAP;

knownObject.equals(unknownObject)

Monday, October 20, 2014

Java Coding Care3: Use DBSPY for Database related issue tracking

Topic : DB SPY

log4jdbc SPY should be use for DB related issue Tracking/Logs

Advantage
It is useful to SPY / DEBUG database related issue tracking. It generates all kind of user
required logs


Libs Required
log4j-1.2.16.jar
log4jdbc4-1.2.jar
log4j-over-slf4j-1.7.5.jar
slf4j-api.jar"
slf4j-jdk14.jar"
slf4j-log4j12-1.7.5.jar"
slf4j-simple-1.7.5.jar"

ojdbc6-11.0.2.0.jar"

Example
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class SpyEngine {

public static void main(String[] rk) {

try {

  Class.forName("net.sf.log4jdbc.DriverSpy");
Connection conn = DriverManager.getConnection( "jdbc:log4jdbc:oracle:thin:@192.168.8.87:1521:rajdb", "rajusername", "rajpassword");

PreparedStatement prStmt = conn.prepareStatement("select * from tbdata");
prStmt.execute();
prStmt.close();

  conn.close();
 
} catch (Exception e) {
System.out.println("Error: " + e);

}
}

Sunday, October 19, 2014

Java Coding Care2 : Prepare TLD in jsp

Topic : TLD (Tag Library Descriptor)

Prepare TLD in jsp for some common features and tags

Example
Need /Use the custom prepared TLD tag. For some common code we can
prepare custom TLD tags (i.e Logo, specifc conditional statements)


Advantage
No dependency on others tags

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...