To get client browser information :
String client = request.getHeader("User-Agent");
To get content length :
String content = request.getHeader("Content-Length");
To get router hops allowed for request :
String maxForwards = request.getHeader("Max-Forwards");
To get accepted encoding details :
String encoding = request.getHeader("Accept-Encoding");
To get language details :
String language = request.getHeader("Accept-Language");
To get content-type or mime type details :
String mime = request.getHeader("Accept");
To get character set details :
String characterSet = request.getHeader("Accept-Charset");
To get connection status :
String status = request.getHeader("Connection");
Tuesday, November 16, 2010
Monday, November 15, 2010
TCP (Transmission Control Protocol)
TCP is a 16-bit port number used to identify a specific software program on the server hardware.
Port numbers starts from 0 to 65535 and in this 0 to 1023 are reserved for well known services.
Some import port numbers:
21 - FTP (File Transfer Protocol)
23 - Telnet
25 - SMTP (Simple Mail Transfer Protocol)
37 - Time
80 - HTTP (Hyper Text Transfer Protocol)
110 - POP2 (Post Office Protocol 2)
443 - HTTPS (Hypertext Transfer Protocol Secure)
Port numbers starts from 0 to 65535 and in this 0 to 1023 are reserved for well known services.
Some import port numbers:
21 - FTP (File Transfer Protocol)
23 - Telnet
25 - SMTP (Simple Mail Transfer Protocol)
37 - Time
80 - HTTP (Hyper Text Transfer Protocol)
110 - POP2 (Post Office Protocol 2)
443 - HTTPS (Hypertext Transfer Protocol Secure)
Sunday, November 14, 2010
Java : Best way to declare a static list constant
public class MyListConstant
{
public static final
List CONSTANT = Collections.unmodifiableList(getConstant());
private static List
getConstant() {
List constant1 = new
ArrayList();
constant1.add("a");
constant1.add("b");
constant1.add("c");
constant1.add("d");
return constant1;
}
}
Note:
- It is better to use Array constants
instead of list constants.
- List constant need to be created with unmodifiableList
method otherwise it will modified with its set method.
CONSTANT.set(1,
"replaced");
Friday, November 12, 2010
Java : Phone number validation using regular expression
package com.lnn.regex;
import
java.util.regex.Matcher;
import
java.util.regex.Pattern;
public class
PhoneNumberValidation {
private static final Pattern PhoneNumberPattern = Pattern.compile("[0-9]{3}[-]{0,1}[0-9]{4}");
public static boolean
isValidPhoneNumber(String phone) {
Matcher
matcher = PhoneNumberPattern.matcher(phone);
return
matcher.matches();
}
public static void main(String[]
args) {
System.out.println(isValidPhoneNumber("123-4567"));
System.out.println(isValidPhoneNumber("1234567"));
}
}
Java Script Regular Expression to restrict repetitive characters in a string
Following java script regular expression will restrict the numbers that contains 4 repetitive digits in a number.
function verifyAccessCode(){
var val = document.forms[0].textbox. value;
var exp1 = new RegExp("1111");
var exp2 = new RegExp("2222");
var exp3 = new RegExp("3333");
var exp4 = new RegExp("4444");
var exp5 = new RegExp("5555");
var exp6 = new RegExp("6666");
var exp7 = new RegExp("7777");
var exp8 = new RegExp("8888");
var exp9 = new RegExp("9999");
var exp10 = new RegExp("0000");
if(exp1.test(val) || exp2.test(val) || exp3.test(val) || exp4.test(val) || exp5.test(val)
|| exp6.test(val) || exp7.test(val) || exp8.test(val) || exp9.test(val) || exp10.test(val)){
return false;
}
return true;
}
function verifyAccessCode(){
var val = document.forms[0].textbox.
var exp1 = new RegExp("1111");
var exp2 = new RegExp("2222");
var exp3 = new RegExp("3333");
var exp4 = new RegExp("4444");
var exp5 = new RegExp("5555");
var exp6 = new RegExp("6666");
var exp7 = new RegExp("7777");
var exp8 = new RegExp("8888");
var exp9 = new RegExp("9999");
var exp10 = new RegExp("0000");
if(exp1.test(val) || exp2.test(val) || exp3.test(val) || exp4.test(val) || exp5.test(val)
|| exp6.test(val) || exp7.test(val) || exp8.test(val) || exp9.test(val) || exp10.test(val)){
return false;
}
return true;
}
Subscribe to:
Posts (Atom)