Archive for the ‘Java’ Category

Spring Framework

  • Transaction Management: Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring’s transaction support is not tied to J2EE environments and it can be also used in container less environments.
  • JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy.
  • Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS.
  • AOP Framework: Spring is best AOP framework
  • MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.

what is Spring Framework?

Popularity: 1% [?]

how to find a string within a string

Find a String within a String:
Search a String “a Nice” is Exist or Not within a String “Have a Nice Day” in JAVA

Coding:

String s = “Have a Nice Day”;
if(s.indexOf(“a Nice”)!=-1)
System.out.println(“string exist==>”);
else
System.out.println(“string Not exist==>”);

Popularity: 1% [?]

Pagination in JSP

Pagination Using Display Tag :

If you would like to make use of the display taglib in your own application, do the following

1.Drop the displaytag-version.jar file in your application WEB-INF/lib directory
2.Make sure that following libraries are in your WEB-INF/lib directory (or made available via the classpath to your application server). Refer to the dependencies document for the correct version of these libraries. The following is the list of dependencies:

  • commons-logging
  • commons-lang
  • commons-collection
  • commons-beanutils
  • log4j
  • 3.Include this tag in the JSP File

    <%@ taglib uri=”http://displaytag.sf.net” prefix=”display”%>

    4.Using Display tag the Code is:
    1.Header Data Can be given in title and Corresponding Display data will be given in property in display:column tag
    Ex:

    <display:column property=”name” title=”Name”/>

    2.Array List name will be given in name,Default page Size will be given in pagesize and id will denote arraylist variable in display:table tag

    <display:table name=”requestScope.arraydetails” defaultsort=”7″ defaultorder=”ascending” pagesize=”10″ id=”list” requestURI=”" >

    <display:setProperty name=”paging.banner.group_size”<5>/display:setProperty>
    <display:setProperty name=”css.tr.even”<even_grid>/display:setProperty>
    <display:setProperty name=”css.tr.odd”<odd_grid>/display:setProperty>
    <display:setProperty name=”basic.msg.empty_list” value=” ” / >
    <display:setProperty name=”paging.banner.one_item_found” value=” ” />
    <display:setProperty name=”paging.banner.all_items_found” value=”Page ” />
    <display:setProperty name=”paging.banner.some_items_found” value=” ” />
    <display:setProperty name=”paging.banner.no_items_found” value=” ” />
    <display:setProperty name=”paging.banner.placement” value=”bottom” />

    <display:column property=”name” title=”Name”/>
    <display:column property=”age” title=”Age”/>
    <display:column property=”designation” title=”Designation”/>

    </display:table >

    Popularity: 11% [?]

    JSP Applet tag

    How to Include Applet Program in a JSP Page:

    1.Create a Applet Java Program

    sample.java

    import javax.swing.JApplet;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;  
     
    public class sample extends Applet {
     
    sampleCanvas canvas;       // The drawing area to display arcs
    public static String s=null;
     
    public void init() {
    setLayout(new BorderLayout());
    canvas = new sampleCanvas();
    add("Center", canvas);
    s=this.getParameter("data");
    }
     
    public void destroy() {
    remove(canvas);
    }
     
    public void start() {
    }
     
    public void stop() {
    }
     
    public void processEvent(AWTEvent e) {
    if (e.getID() == Event.WINDOW_DESTROY) {
    System.exit(0);
    }
    }
     
    }
     
    class sampleCanvas extends Canvas {
    font = new java.awt.Font("SansSerif", Font.PLAIN, 12);
     
    public void paint(Graphics g) {
    Rectangle r = getBounds();
     
    if(sample.s==null)
    sample.s="0";
    int a = Integer.parseInt(sample.s);
    a=(a*600)/1000;
     
    g.fillRect(10, 200,a, 25);
     
    }
     
    public void redraw(int value) {
    this.filled = filled;
    this.startAngle = value;
    repaint();
    }
    }

    2.Complie the Applet Program

    3.Import the applet Program in the JSP File

    <%@page import="com.sample">

    4.Include this Tag in the JSP File

    <jsp:plugin type="applet" code="sample.class" width="620" height="450">
    <jsp:params>
    <jsp:param name="data" value="10"/>
    </jsp:params>
    </jsp:plugin> 

    Popularity: 3% [?]

    JSP Custom tags Example


    Custom tags are usually distributed in the form of a tag library, which defines a set of related custom tags and contains the objects that implement the tags.

    A Simple Custom tags Example:

    1.Create a Java Program

    2.import javax.servlet.jsp.*,javax.servlet.jsp.tagext.* packages

    3.Extends the TagSupport Class

    4.Java Program Contain two Default Methods.
    a)doStartTag
    b)doEndTag

    doStartTag:
    1.The doStartTag method is invoked when the start tag is encountered
    2.This method returns SKIP_BODY because a simple tag has no body

    doEndTag:
    1.The doEndTag method is invoked when the end tag is encountered
    2.This method returns SKIP_BODY because a simple tag has no body

    TagClass.java

    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;

    public class TagClass extends TagSupport{

    private String data=null;

    public void setData(String value){
    data= value;
    }

    public String getData(){
    return(data);
    }

    public int doStartTag()throws JspException{
    try{
    JspWriter out=pageContext.getOut();
    out.println(name);

    }catch(Exception e){}
    return SKIP_BODY;
    }

    public int doEndTag(){
    return SKIP_BODY;
    }

    }

    5.The Java Program Contain one Variable data(which has Getter and Setter Methods)

    6.Create tld File.

    7.We have to Create attribute For the Variable data

    8.Syntax For Creating attribute:

    <taglib>

    <tag>

    <attribute>
    <name>data</name>//Name Can be Same as we can given within the tags
    <required>true</required>//Requried Field Show Whether it is Mandatory or Not
    </attribute>

    <attribute>
    <name>id</name>
    <required>false</required>
    </attribute>

    </tag>

    </taglib>

    taglib.tld

    <?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
    <!DOCTYPE taglib PUBLIC “-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN” “http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd”>

    <taglib>

    <tlib-version>1.0</tlib-version>

    <jsp-version>1.2</jsp-version>

    <short-name>form</short-name>

    <tag>

    <name>Show</name>
    <tag-class>com.TagClass</tag-class>
    <body-content>JSP</body-content>
    <description>Simple Customs tags Example</description>

    <attribute>
    <name>data</name>
    <required>true</required>
    </attribute>

    </tag>

    </taglib>

    9.Create a JSP Page.

    10.Include this tag at the begining of the JSP Page

    <%@ taglib uri=”/WEB-INF/tld/taglib.tld” prefix=”custom” %>

    11.Create this Tag at the JSP Page

    <custom:Show data=”Custom Tag Example”></custom:Show>

    12.Output:

    Custom Tag Example

    Popularity: 11% [?]

    Custom tags in JSP

    Custom tags :
    Custom tags are usually distributed in the form of a tag library, which defines a set of related custom tags and contains the objects that implement the tags.

    Ex:-
    <%@ taglib uri="/WEB-INF/tld/taglib.tld" prefix="custom" %>

    what is Custom tags?

    A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on an object called a tag handler. The Web container then invokes those operations when the JSP page’s servlet is executed.

    Custom tags have a rich set of features. They can

    • Be customized via attributes passed from the calling page.
    • Access all the objects available to JSP pages.
    • Modify the response generated by the calling page.
    • Communicate with each other. You can create and initialize a JavaBeans component, create a variable that refers to that bean in one tag, and then use the bean in another tag.
    • Be nested within one another, allowing for complex interactions within a JSP page.

    Popularity: 1% [?]

    Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars