Pages

Make a WAR and JAR Using ANT build Tool


ANT is a build tool for java web based application. It is used to clean,compile,create a war and jar files. Create a xml called build.xml under WEB-INF.

<?xml version="1.0" encoding="UTF-8"?>
<project name="sample">
    <target name="makeJAR"> 
         <mkdir dir="build/jar"/>
        <jar destfile="build/jar/sample.jar" basedir="build/classes">            
        </jar>
    </target>
    <target name="makeWAR" description="Bundles the application as a WAR file">
        <war destfile="sample.war" basedir="WebContent">
        </war>
    </target>
</project>

Now build your application. WAR and JAR are created.

Put Taglib in WEB.XML


Put your struts taglib files in Web-Inf and specify the below code in Web.Xml

Below XML attributes are load the taglib in jsp and parse the HTML elements.


Convert String to Int


Convert string to int variable that may do arithmetic operaton.
Here is the code to convert
{
     String month="25";
     int count=0;
     count=count+Integer.parseInt(month);
     System.out.println("Count is " + count);
}

Output :
Count is 25

Using indexOf()

indexOf function is used to find the character in a String. It will return '-1' on failure i.e. no character found in a String else it will return the position of the character.

Example
public class example
{
    public static void main(String[] args)
    {
          String email="example@gmail.com";
          int pos=email.indexOf('@');
          if(pos!=-1)
          {
                  System.out.println("@ Special Character Found in a postion "+pos);
           }
          else
          {
                  System.out.println("@ Special Character Not Found");
          }
     }
}
Output
@ Special Character Found in a postion 7

Remove Special Characters in a String - Java

To remove special characters in a string, replaceAll is used.Example of replaceAll follows below











public class example
{
     public static void main(String[] args)
     {
          String price="$5.00";
          String newPrice=price.replaceAll("\\$","");
          System.out.println("New Price "+newPrice);
     }
}

Output:
New Price 5.00

Remove jsessionid in URL - Struts


URL Rewriting is used to remove the URL jsesssionid in java based web application.By default, Web app URL are look like this :
http://www.bhuvanlabs.com/login.do;jsessionid=539F373633D345

Above URL fails in Security concerns because session is maintain in URL. User can miss use the data by session Id.It's possible that some web sites may use cookies to track user browsing patterns.
Sessions can be implemented with two underlying mechanism
-->cookies
-->URL rewriting

To remove the jsessionid , want to tell in web.xml
<session-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>
Now URL look like this..
http://www.bhuvaneslabs.com/login.do