Tuesday, June 30, 2009

Using GET and POST method in XMLHTTPRequest(Ajax) PHP Java Jsp

Requirements
Create a XMLHTTPRequest Object that uses the POST method.var http = new XMLHttpRequest();

Using GET method
Now we open a connection using the GET method.var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("GET“, url+”?”+params, true);
http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);}}
http.send(null);

I really hope that this much is clear for you
POST method
We are going to make some modifications so POST method will be used when sending the request…

var url = "get_data.php";
var params = "lorem=ipsum&name=binny";
http.open("POST“, url, true);
//Send the proper header information along with the request
http.setRequestHeader(”Content-type”, “application/x-www-form-urlencoded”);
http.setRequestHeader(”Content-length”, params.length);
http.setRequestHeader(”Connection”, “close”);
http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);}}
http.send(params);
The first change(and the most obvious one) is that I changed the first argument of the open function from GET to POST. Also notice the difference in the second argument – in the GET method, we send the parameters along with the url separated by a ‘?’ character…http.open("GET",url+”?”+params, true);

But in the POST method we will use just the url as the second argument. We will send the parameters later.http.open("POST", url, true);

Some http headers must be set along with any POST request. So we set them in these lines…http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

With the above lines we are basically saying that the data send is in the format of a form submission. We also give the length of the parameters we are sending.

http.onreadystatechange = function() {
//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);}}

We set a handler for the ‘ready state’ change event. This is the same handler we used for the GET method. You can use the http.responseText here – insert into a div using innerHTML(AHAH), eval it(JSON) or anything else.
http.send(params);

Saturday, June 27, 2009

Syntax in jsp

Legend All tags are case sensitive.
A pair of single quotes is equivalent to a pair of double quotes.
Spaces are not allowed between an equals sign and an attribute value.

plain text = required bold = default italics = user-defined | = or
[ ] = optional { } = required choice ... = list of items + = can repeat
HTML Comment Creates a comment that is sent to the client in the viewable page source.

Hidden Comment Documents the JSP file, but is not sent to the client.
<%-- comment --%>

Declaration Declares variables or methods valid in the page scripting language.
<%! declaration; [ declaration; ]+ ... %>

Expression Contains an expression valid in the page scripting language.
<%= expression %>

Scriptlet Contains a code fragment valid in the page scripting language.
<% code fragment of one or more lines %>

Include Directive Includes a static file, parsing the file’s
JSP elements.
<%@ include file="relativeURL" %>

Page Directive Defines attributes that apply to an entire JSP page.
<%@ page [ language="java" ] [ extends="package.class" ] [ import="{package.class | package.*} , ... " ] [ session="true|false" ] [ buffer="none|8kb|sizekb" ] [ autoFlush="true|false" ] [ isThreadSafe="true|false" ] [ info="text" ] [ errorPage="relativeURL" ] [ contentType="{mimeType [ ; charset=characterSet ] | text/html ; charset=ISO-8859-1}" ] [ isErrorPage="true|false" ] %>

Taglib Directive Defines a tag library and prefix for the custom tags used in the JSP page.
<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>

Accesses a custom tag’s functionality. other tags and data
Forwards a client request to an HTML
file, JSP file, or servlet for processing.
}"
{ /> |
> [ }" /> ]+
}

Gets the value of a bean property so that
you can display it in a result page.


Includes a static file or sends a request to a dynamic file.
}" flush="true"
{ /> |
> [ }" /> ]+
}

Downloads plug-in software to the Web
browser to execute an applet or bean.
[ name="instanceName" ] [ archive="URIToArchive, ..." ] [ align="bottom|top|middle|left|right" ]
[ height="displayPixels" ] [ width="displayPixels" ] [ hspace="leftRightPixels" ] [ vspace="topBottomPixels" ]
[ jreversion="JREVersionNumber | 1.1" ] [ nspluginurl="URLToPlugin" ] [ iepluginurl="URLToPlugin" ] >
[ [ }" /> ]+
]
[ text message for user ]

Sets a property value or values in a
bean.
{ property="*" | property="propertyName" [ param="parameterName" ] |
property="propertyName" value="{string | <%= expression %>}" } />
Locates or instantiates a bean with a
specific name and scope.
{ class="package.class" [ type="package.class" ] | type="package.class" |
beanName="{package.class | <%= expression %>}" type="package.class" }
{ /> | > other elements
}

Implicit Objects Type Scope Some Useful Methods (see class or interface for others)
request Subclass of javax.servlet.ServletRequest Request getAttribute, getParameter, getParameterNames, getParameterValues, setAttribute
response Subclass of javax.servlet.ServletResponse Page Not typically used by JSP page authors
pageContext javax.servlet.jsp.PageContext Page findAttribute, getAttribute, getAttributesScope, getAttributeNamesInScope, setAttribute

session javax.servlet.http.HttpSession Session getAttribute, getId, setAttribute
application javax.servlet.ServletContext Application getAttribute, getMimeType, getRealPath, setAttribute

out javax.servlet.jsp.JspWriter Page clear, clearBuffer, flush, getBufferSize, getRemaining
config javax.servlet.ServletConfig Page getInitParameter, getInitParameterNames
page java.lang.Object Page Not typically used by JSP page authors
exception java.lang.Throwable Page getMessage, getLocalizedMessage, printStackTrace, toString

Thursday, June 11, 2009

Operator and Function Reference in mysql

 Operator and Function Reference

Name Description
ABS() Return the absolute value
ACOS() Return the arc cosine
ADDDATE()(v4.1.1) Add dates
ADDTIME()(v4.1.1) Add time
AES_DECRYPT() Decrypt using AES
AES_ENCRYPT() Encrypt using AES
AND, && Logical AND
ASCII() Return numeric value of left-most character
ASIN() Return the arc sine
ATAN2(), ATAN() Return the arc tangent of the two arguments
ATAN() Return the arc tangent
AVG() Return the average value of the argument
BENCHMARK() Repeatedly execute an expression
BETWEEN ... AND ... Check whether a value is within a range of values
BIN() Return a string representation of the argument
BINARY Cast a string to a binary string
BIT_AND() Return bitwise and
BIT_COUNT() Return the number of bits that are set
BIT_LENGTH() Return length of argument in bits
BIT_OR() Return bitwise or
BIT_XOR()(v4.1.1) Return bitwise xor
& Bitwise AND
~ Invert bits
| Bitwise OR
^ Bitwise XOR
CASE Case operator
CAST() Cast a value as a certain type
CEIL() Return the smallest integer value not less than the argument
CEILING() Return the smallest integer value not less than the argument
CHAR_LENGTH() Return number of characters in argument
CHAR() Return the character for each integer passed
CHARACTER_LENGTH() A synonym for CHAR_LENGTH()
CHARSET()(v4.1.0) Return the character set of the argument
COALESCE() Return the first non-NULL argument
COERCIBILITY()(v4.1.1) Return the collation coercibility value of the string argument
COLLATION()(v4.1.0) Return the collation of the string argument
COMPRESS()(v4.1.1) Return result as a binary string
CONCAT_WS() Return concatenate with separator
CONCAT() Return concatenated string
CONNECTION_ID() Return the connection ID (thread ID) for the connection
CONV() Convert numbers between different number bases
CONVERT_TZ()(v4.1.3) Convert from one timezone to another
Convert() Cast a value as a certain type
COS() Return the cosine
COT() Return the cotangent
COUNT(DISTINCT) Return the count of a number of different values
COUNT() Return a count of the number of rows returned
CRC32()(v4.1.0) Compute a cyclic redundancy check value
CURDATE() Return the current date
CURRENT_DATE(), CURRENT_DATE Synonyms for CURDATE()
CURRENT_TIME(), CURRENT_TIME Synonyms for CURTIME()
CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP Synonyms for NOW()
CURRENT_USER(), CURRENT_USER Return the username and hostname combination
CURTIME() Return the current time
DATABASE() Return the default (current) database name
DATE_ADD() Add two dates
DATE_FORMAT() Format date as specified
DATE_SUB() Subtract two dates
DATE()(v4.1.1) Extract the date part of a date or datetime expression
DATEDIFF()(v4.1.1) Subtract two dates
DAY()(v4.1.1) Synonym for DAYOFMONTH()
DAYNAME()(v4.1.21) Return the name of the weekday
DAYOFMONTH() Return the day of the month (0-31)
DAYOFWEEK() Return the weekday index of the argument
DAYOFYEAR() Return the day of the year (1-366)
DECODE() Decodes a string encrypted using ENCODE()
DEFAULT() Return the default value for a table column
DEGREES() Convert radians to degrees
DES_DECRYPT() Decrypt a string
DES_ENCRYPT() Encrypt a string
DIV(v4.1.0) Integer division
/ Division operator
ELT() Return string at index number
ENCODE() Encode a string
ENCRYPT() Encrypt a string
<=> NULL-safe equal to operator
= Equal operator
EXP() Raise to the power of
EXPORT_SET() Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string
EXTRACT Extract part of a date
ExtractValue()(v5.1.5) Extracts a value from an XML string using XPath notation
FIELD() Return the index (position) of the first argument in the subsequent arguments
FIND_IN_SET() Return the index position of the first argument within the second argument
FLOOR() Return the largest integer value not greater than the argument
FORMAT() Return a number formatted to specified number of decimal places
FOUND_ROWS() For a SELECT with a LIMIT clause, the number of rows that would be returned were there no LIMIT clause
FROM_DAYS() Convert a day number to a date
FROM_UNIXTIME() Format UNIX timestamp as a date
GET_FORMAT()(v4.1.1) Return a date format string
GET_LOCK() Get a named lock
>= Greater than or equal operator
> Greater than operator
GREATEST() Return the largest argument
GROUP_CONCAT()(v4.1) Return a concatenated string
HEX() Return a hexadecimal representation of a decimal or string value
HOUR() Extract the hour
IF() If/else construct
IFNULL() Null if/else construct
IN() Check whether a value is within a set of values
INET_ATON() Return the numeric value of an IP address
INET_NTOA() Return the IP address from a numeric value
INSERT() Insert a substring at the specified position up to the specified number of characters
INSTR() Return the index of the first occurrence of substring
INTERVAL() Return the index of the argument that is less than the first argument
IS_FREE_LOCK() Checks whether the named lock is free
IS NOT NULL NOT NULL value test
IS NOT Test a value against a boolean
IS NULL NULL value test
IS_USED_LOCK()(v4.1.0) Checks whether the named lock is in use. Return connection identifier if true.
IS Test a value against a boolean
ISNULL() Test whether the argument is NULL
LAST_DAY(v4.1.1) Return the last day of the month for the argument
LAST_INSERT_ID() Value of the AUTOINCREMENT column for the last INSERT
LCASE() Synonym for LOWER()
LEAST() Return the smallest argument
<< Left shift
LEFT() Return the leftmost number of characters as specified
LENGTH() Return the length of a string in bytes
<= Less than or equal operator
< Less than operator
LIKE Simple pattern matching
LN() Return the natural logarithm of the argument
LOAD_FILE() Load the named file
LOCALTIME(), LOCALTIME Synonym for NOW()
LOCALTIMESTAMP, LOCALTIMESTAMP()(v4.0.6) Synonym for NOW()
LOCATE() Return the position of the first occurrence of substring
LOG10() Return the base-10 logarithm of the argument
LOG2() Return the base-2 logarithm of the argument
LOG() Return the natural logarithm of the first argument
LOWER() Return the argument in lowercase
LPAD() Return the string argument, left-padded with the specified string
LTRIM() Remove leading spaces
MAKE_SET() Return a set of comma-separated strings that have the corresponding bit in bits set
MAKEDATE()(v4.1.1) Create a date from the year and day of year
MAKETIME(v4.1.1) MAKETIME()
MASTER_POS_WAIT() Block until the slave has read and applied all updates up to the specified position
MATCH Perform full-text search
MAX() Return the maximum value
MD5() Calculate MD5 checksum
MICROSECOND()(v4.1.1) Return the microseconds from argument
MID() Return a substring starting from the specified position
MIN() Return the minimum value
- Minus operator
MINUTE() Return the minute from the argument
MOD() Return the remainder
% Modulo operator
MONTH() Return the month from the date passed
MONTHNAME()(v4.1.21) Return the name of the month
NAME_CONST()(v5.0.12) Causes the column to have the given name
NOT BETWEEN ... AND ... Check whether a value is not within a range of values
!=, <> Not equal operator
NOT IN() Check whether a value is not within a set of values
NOT LIKE Negation of simple pattern matching
NOT REGEXP Negation of REGEXP
NOT, ! Negates value
NOW() Return the current date and time
NULLIF() Return NULL if expr1 = expr2
OCT() Return an octal representation of a decimal number
OCTET_LENGTH() A synonym for LENGTH()
OLD_PASSWORD()(v4.1) Return the value of the old (pre-4.1) implementation of PASSWORD
||, OR Logical OR
ORD() Return character code for leftmost character of the argument
PASSWORD() Calculate and return a password string
PERIOD_ADD() Add a period to a year-month
PERIOD_DIFF() Return the number of months between periods
PI() Return the value of pi
+ Addition operator
POSITION() A synonym for LOCATE()
POW() Return the argument raised to the specified power
POWER() Return the argument raised to the specified power
PROCEDURE ANALYSE() Analyze the results of a query
QUARTER() Return the quarter from a date argument
QUOTE() Escape the argument for use in an SQL statement
RADIANS() Return argument converted to radians
RAND() Return a random floating-point value
REGEXP Pattern matching using regular expressions
RELEASE_LOCK() Releases the named lock
REPEAT() Repeat a string the specified number of times
REPLACE() Replace occurrences of a specified string
REVERSE() Reverse the characters in a string
>> Right shift
RIGHT() Return the specified rightmost number of characters
RLIKE Synonym for REGEXP
ROUND() Round the argument
ROW_COUNT()(v5.0.1) The number of rows updated
RPAD() Append string the specified number of times
RTRIM() Remove trailing spaces
SCHEMA()(v5.0.2) A synonym for DATABASE()
SEC_TO_TIME() Converts seconds to 'HH:MM:SS' format
SECOND() Return the second (0-59)
SESSION_USER() Synonym for USER()
SHA1(), SHA() Calculate an SHA-1 160-bit checksum
SIGN() Return the sign of the argument
SIN() Return the sine of the argument
SLEEP()(v5.0.12) Sleep for a number of seconds
SOUNDEX() Return a soundex string
SOUNDS LIKE(v4.1.0) Compare sounds
SPACE() Return a string of the specified number of spaces
SQRT() Return the square root of the argument
STD() Return the population standard deviation
STDDEV_POP()(v5.0.3) Return the population standard deviation
STDDEV_SAMP()(v5.0.3) Return the sample standard deviation
STDDEV() Return the population standard deviation
STR_TO_DATE()(v4.1.1) Convert a string to a date
STRCMP() Compare two strings
SUBDATE() A synonym for DATE_SUB() when invoked with three arguments
SUBSTR() Return the substring as specified
SUBSTRING_INDEX() Return a substring from a string before the specified number of occurrences of the delimiter
SUBSTRING() Return the substring as specified
SUBTIME()(v4.1.1) Subtract times
SUM() Return the sum
SYSDATE() Return the time at which the function executes
SYSTEM_USER() Synonym for USER()
TAN() Return the tangent of the argument
TIME_FORMAT() Format as time
TIME_TO_SEC() Return the argument converted to seconds
TIME()(v4.1.1) Extract the time portion of the expression passed
TIMEDIFF()(v4.1.1) Subtract time
* Times operator
TIMESTAMP()(v4.1.1) With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments
TIMESTAMPADD()(v5.0.0) Add an interval to a datetime expression
TIMESTAMPDIFF()(v5.0.0) Subtract an interval from a datetime expression
TO_DAYS() Return the date argument converted to days
TRIM() Remove leading and trailing spaces
TRUNCATE() Truncate to specified number of decimal places
UCASE() Synonym for UPPER()
- Change the sign of the argument
UNCOMPRESS()(v4.1.1) Uncompress a string compressed
UNCOMPRESSED_LENGTH()(v4.1.1) Return the length of a string before compression
UNHEX()(v4.1.2) Convert each pair of hexadecimal digits to a character
UNIX_TIMESTAMP() Return a UNIX timestamp
UpdateXML()(v5.1.5) Return replaced XML fragment
UPPER() Convert to uppercase
USER() Return the current username and hostname
UTC_DATE()(v4.1.1) Return the current UTC date
UTC_TIME()(v4.1.1) Return the current UTC time
UTC_TIMESTAMP()(v4.1.1) Return the current UTC date and time
UUID_SHORT()(v5.1.20) Return an integer-valued universal identifier
UUID()(v4.1.2) Return a Universal Unique Identifier (UUID)
VALUES()(v4.1.1) Defines the values to be used during an INSERT
VAR_POP()(v5.0.3) Return the population standard variance
VAR_SAMP()(v5.0.3) Return the sample variance
VARIANCE()(v4.1) Return the population standard variance
VERSION() Returns a string that indicates the MySQL server version
WEEK() Return the week number
WEEKDAY() Return the weekday index
WEEKOFYEAR()(v4.1.1) Return the calendar week of the date (0-53)
XOR Logical XOR
YEAR() Return the year
YEARWEEK() Return the year and week