Pages

Subscribe Twitter Twitter

Saturday, June 17, 2006

[java] Read properties

Enumeration e =System.getProperties().propertyNames();
Object obj;        
while( e.hasMoreElements()){
    obj = e.nextElement();            
    System.out.println(obj + " = " + System.getProperty(obj.toString()));
}

Monday, May 22, 2006

javascript simulated query string

function getRequest(requestName) 
{ 
     var url=location.search.toLowerCase(); 
     var Request = new Object(); 

     if(url.indexOf("?")!=-1){ 
          var str=url.substr(1);
          strs = str.split("&"); 
          for(var i=0;i<strs.length;i++){    
               Request[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
          }    
     } 
     return(Request[requestName]); 

} 

javascript return value to opener

if (window.opener && !window.opener.closed)  
    window.opener.document.Form1.fileName.value ="aaa"; 

Tuesday, May 16, 2006

Export file from web page (JSP)

<%@page contentType="text/html;charset=MS950"%>
<%@page pageEncoding="MS950"%>
<%
    String m_filename = "hello.txt ";
    String m_content = "Hello\nWorld";
    response.addHeader("Content-Disposition", "attachment; filename=" + m_filename);
    response.setContentType("text/plain"); 
    response.getWriter().write(m_content);
%>

Monday, May 15, 2006

prevent right click(Javascript)

var message="Function Disabled!";

function clickIE4(){
  if (event.button==2){
  //alert(message);
  return false;
}
}

function clickNS4(e){
  if (document.layersdocument.getElementById&&!document.all){
     if (e.which==2e.which==3){
    //alert(message); return false; } } }
if (document.layers){
 document.captureEvents(Event.MOUSEDOWN);
 document.onmousedown=clickNS4; }
 else if (document.all&&!document.getElementById){
  document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("return false")

Thursday, May 11, 2006

How to add audio file in HTML img tag?

Add audio file in your img tag, such that your picture can sing.
It is funny.


Wednesday, March 01, 2006

Add some javascript in web control

How to check something before clicking web control button?

In client side:(javascript)
function Check_function(){
  if(checkIsOk)
    return true;
  else
  return false;
}

In Server side:
button1 is a ID of web control button.
button1Attributes.Add("onclick","if(Check_function()==false) return false;");

Monday, February 27, 2006

Java : Convert from type X to type Y

[refer from http://www.rgagnon.com/javadetails/java-0004.html]

Convert from type X to type Y


integer to String :
int i = 42;
String str = Integer.toString(i);
or
String str = "" + i
double to String :
String str = Double.toString(i);
long to String :
String str = Long.toString(l);
float to String :
String str = Float.toString(f);



String to integer :
str = "25";
int i = Integer.valueOf(str).intValue();
or
int i = Integer.parseInt(str);
String to double :
double d = Double.valueOf(str).doubleValue();
String to long :
long l = Long.valueOf(str).longValue();
or
long l = Long.parseLong(str);
String to float :
float f = Float.valueOf(str).floatValue();


decimal to binary :
int i = 42;
String binstr = Integer.toBinaryString(i);


decimal to hexadecimal :
int i = 42;
String hexstr = Integer.toString(i, 16);
or
String hexstr = Integer.toHexString(i);
or (with leading zeroes and uppercase)
public class Hex {
public static void main(String args[]){
int i = 42;
System.out.print
(Integer.toHexString( 0x10000 | i).substring(1).toUpperCase());
}
}


hexadecimal (String) to integer :
int i = Integer.valueOf("B8DA3", 16).intValue();
or
int i = Integer.parseInt("B8DA3", 16);     



ASCII code to String
int i = 64;
String aChar = new Character((char)i).toString();


integer to ASCII code (byte)
char c = 'A';
int i = (int) c; // i will have the value 65 decimal


To extract Ascii codes from a String
String test = "ABCD";
for ( int i = 0; i < test.length(); ++i ) {
char c = test.charAt( i );
int j = (int) c;
System.out.println(j);
}
integer to boolean
b = (i != 0);
boolean to integer
i = (b)?1:0;

note :To catch illegal number conversion, try using the try/catch mechanism.
try{
i = Integer.parseInt(aString);
}
catch(NumberFormatException e)
{
}

Saturday, February 25, 2006

How to clean the IE browser cache?

<script language="javascript">
document.execCommand("ClearAuthenticationCache","false");
</script>