Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

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