Saturday, 6 October 2012

How to use session in Java web Project

Creating / Using session : Java Web Project



// NameSpace imports
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
/* Use openSymphony .jar for above import
//Declaration of Session
private Map session;
//Create setter getter
session = ActionContext.getContext().getSession();
//Use session.put & session.get
session.put(“Id”,userID );
String userId = (String)session.get(“Id”);

Append apostrophe with string or string items

Append apostrophe with string or string items

This code would help in appending apostrophe with the string on both ends.
If there are comma separated items in string, each one would be appended with apostrophes.
Use: Appending apostrophe for query IN clause


public static final String appendAppsotophe(String str) {
            if(str!=null) {
                  String returnData = "";
                  String array[] = str.split(",");
                  returnData = "'" + array[0] + "'";
                  for (int i = 1; i < array.length; i++) {
                        returnData += ",'" + array[i].trim() + "'";
                  }
                  return returnData;
            } else {
                  return null;
            }
      }

forouzan data communication and networking

Download forouzan data communication and networking ebook here
Download Link:
http://www.mediafire.com/?mmzmmnjmvmn 

How to animate web buttons

Animate web buttons (zoom in zoom out)

Exactly not an animation. Use this javascript code to zoom in zoom out buttons on mouse hover.

--- Below is Javascript code ---



function buttonZoom(id){
      var x = Number(document.getElementById(id).width);
      for(var i=x; i<=Number(x+20); i++){
            document.getElementById(id).width = Number(i);
      }
    }
   
    function buttonZoomOut(id){
      var x = Number(document.getElementById(id).width);
      for(var i=x; i>=Number(x-20); i--){
            document.getElementById(id).width = Number(i);
      }
    }
----- Below is JSP Code ---
<embed id="button" type="image/svg+xml" src="" onclick="as();"
onmouseover="buttonZoom(this.id);" onmouseout="buttonZoomOut(this.id);" width="60"/>

Note: Specifying width in jsp embed tag is necessary

Check textbox for email format : javascript

Check textbox for email format : javascript

email format validation
check textbox for email format
check format of email id

-- Check html/ jsp textbox for email address format  --

//Use this function in javascript.
//Call the function @ textbox onChange event
function checkemail(email,errorMail)
      {          
            var testresults;
            var str=document.getElementById(email).value;
            var filter=/^.+@.+\..{2,3}$/;
            if (filter.test(str)){
                 document.getElementById(errorMail).style.display="none";
                 testresults=true;
            }
            else
            {    
                  document.getElementById(errorMail).style.display="block";
                  testresults=false;
            }
            return testresults;
}

AAA Logo full version

Design your Logo
with this logo designing software AAA Logo
Download Link:
http://www.mediafire.com/?ozxh8tb1f8c4f42

How to use bind variables in query

Using Bind Variables in query

How to use bind variables

//Following code helps to use bind variables in java and Oracle query
import org.hibernate.SessionFactory;
private SessionFactory sessionFactory;
public void method() {
      Session session = null;
      String  studentId = “R16”;
            try {
            session = sessionFactory.openSession();
String sql_select_query = "select name, class, age from class_table where id = :studentId";
            Query query = session.createSQLQuery(sql_select_query);
            query.setString("studentId", studentId);
                  List<Object[]> list = query.list();
      }          
 }
//Use catch or finally block with the above code
//Also use hibernate .jar file to implement above code