Two types of data are sent to the server: get and post.
First, replace the html code in the body
<Button dojoType = "Button" widgetId = "helloButton"> Hello World! </Button>
<Br>
Enter the name: <input type = "text" id = "name">
If you do not enter data, how can you submit the data.
- Get
We only need:
Function helloPressed ()
{
Dojo. io. bind ({
Url: 'response.txt ',
Handler: helloCallback
});
}
Replace:
function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponseGET.jsp',
handler: helloCallback,
content: {name: dojo.byId('name').value }
});
}
Now, the URL in the example can be clearly described. The example is relative. The example is in the current directory of helloworld.html.
There should be a HelloWorldResponseGET. jsp file. handler is still the same, processing the returned data,
If yes.
Content is the data to be sent. The name and name are the values you enter.
In this way, we can write simple code in jsp to get this value. The following is the code in jsp.
<%
/*
'Helloworldresponseget. jsp
'--------
'
'Print the name value.
'
*/
Response. setContentType ("text/plain ");
%>
Hello <% = request. getParameter ("name") %>. Welcome to the dojo world!
- Post
This method submits data in the form.
The corresponding html code is:
<Button dojoType = "Button" widgetId = "helloButton"> Hello World! </Button>
<Br>
<Form id = "myForm" method = "POST">
Enter the name: <input type = "text" name = "name">
</Form>
The dojo code is:
function helloPressed()
{
dojo.io.bind({
url: 'HelloWorldResponsePOST.jsp',
handler: helloCallback,
formNode: dojo.byId('myForm')
});
}
Here, the content attribute is changed to the formNode attribute.
The jsp code remains unchanged.
Here, the basics of dojo have come to an end. These contents come from the official website of dojo. For more details, see the official website.
Http://dojo.jot.com/WikiHome/Tutorials/HelloWorld