October 20 Ajax and JSP training diary

Source: Internet
Author: User

Teacher Liang Yanbing explained Ajax and a real Ajax project recently developed in the next two days. Therefore, I want to explain some of the prerequisites required by teacher Liang's courses today.
Because you are not very familiar with JavaScript, I will first explain the DHTML function of JavaScript. Originally, the entrance exam required everyone to have a good understanding of JavaScript, but everyone could not understand our difficulties and did not focus on JavaScript. When I emphasized the importance of JavaScript and CSS in the past two years, some training center people did not care about it. When they consulted students, they also attacked me, the trainees are also convinced by the temptation of these training centers! With the popularity of Ajax, these people are following the trend and think Javascript is important. Now, students should be able to calm down and study JavaScript well.
DHTML and javascript can be used to implement partial update of web page display. The following two methods are provided:
Table-specific data models:
<Script language = JavaScript>
Function lianjie ()
{
// Selvalue = maintab. Rows [0]. cells [0]. childnodes [0]. innertext;
// Selvalue = Window. Sel. innertext
Selvalue = Window. Sel. Options [window. Sel. selectedindex]. Text
Texvalue = Window. text1.value;
Innvalue = selvalue + texvalue;
Newrow = Window. maintab [1]. insertrow ()
Alert (newrow );
Newcell = newrow. insertcell ()
Newcell. innertext = innvalue;
}
</SCRIPT>
<Table id = "maintab">
<Tr>
<TD>
<Select style = "width: 200px;" id = "Sel" name = "Sel">
<Option> sdfsdfsdfdsfsdf </option>
<Option> 1111111111111 </option>
<Option> 222222222222 </option>
</SELECT>
</TD>
<TD>
<Input type = text name = "text1" id = "test1">
</TD>
<Tr>
<Input type = button value = "Connect" onclick = lianjie ()>
<Table>
<Table border = 1 id = "maintab">
</Table>
Implemented through the standard DOM object model:
<HTML>
<Head>
<Title> myhtml.html </title>

<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">

<! -- <LINK rel = "stylesheet" type = "text/CSS" href = "./styles.css"> -->
<SCRIPT type = "text/JavaScript">
Function addrow ()
{
Alert ("hehe ");
VaR tbody = Document. createelement ("tbody ");
VaR TR = Document. createelement ("TR ");
VaR TD = Document. createelement ("TD ");
VaR value = Document. createtextnode ("1111 ");
TD. appendchild (value );
Tr. appendchild (TD );
Tbody. appendchild (TR );
Document. getelementbyid ("T1"). appendchild (tbody );
// Background = "# ff0000 ";
//. Addchild (OBJ );
}

</SCRIPT>
</Head>


<Body>
This is my HTML page. <br>
<Table id = "T1">
<Tr> <TD> 2222 </TD> </tr>
</Table>
<A href = "#" onclick = "addrow ()"> test </a>
</Body>
</Html>

With the intuitive impression of dynamic table generation, I will tell you that the data dynamically needed is not directly obtained from the text box on the webpage, but from the web server. The browser cannot directly access the Web server, because it will get a new webpage instead of retaining the original webpage. To maintain the original web page and allow JavaScript to continue running in the original web page, you should use an object in the web page to connect to the Web server, such as the applet, forum posting is also a good Ajax application.
In JavaScript, you can directly use an XMLHTTPRequest object to send requests to the Web server and receive the results returned by the Web server. The combination of HTML, CSS, JavaScript, XMLHttpRequest and other basic knowledge is Ajax.
Next, I will explain the XMLHttpRequest application through a simple example.
When is Ajax used? After a request is submitted on a page, the server returns the original page, but the data is different, or some fields in the page are verified in advance.

Explains the functions and operating principles of the Ajax framework such as jsonrpc, which encapsulates the underlying communication and the serialization and deserialization of JavaScript objects.

The jsonrpc client constructor sends a request to the server to obtain the objects and methods, and then adds these objects and methods to the client object. Therefore, the client can call jsonrpcclient. hello. sayhello. If you have time, refer to this example to write an experiment that can dynamically add methods to objects.

According to Wang Tao's question, I will explain the URL encoding in detail (this is really confusing to everyone, which is beyond my expectation !), For your understanding
Start with base64 encoding, and then talk about URL encoding.

Http://www.baidu.com? WD = Ajax + % BF % F2 % BC % dc & CL = 3
Reqeust. getparameter ("WD") does not get Ajax + % BF % F2 % BC % DC string,
Getparameter returns a string, and the Java string is a unicode code. how to convert Ajax + % BF % F2 % BC % DC string into a real string is an internal problem of getparamter. but it is really not doing well internally. Because there is no way to describe the character set encoding during URL encoding in the HTTP protocol, I expect this feature should be added in the next generation of HTTP protocol.

Think of the question of an interview: "A's Country B" gb2312 encoding is a byte array. How many characters are identified from this array? First, you must understand that the highest bit of an English character is 0, and the highest bit of a Chinese character is 1. Sample Code:
Byte Buf [] = "Country B in a". getbytes ("gb2312 ");
Int COUNT = 0;
For (INT I = 0; I <Buf. length; I ++)
{
Count ++;
If (BUF [I] & 0x80 )! = 0)
{
I ++;
}
}

As JSP is used in the project of instructor Liang Yanbing, I will give you a brief introduction to How to Use Javabean in JSP and JSP by referring to the book "deep experience Java Web development insider. Focus on the JSP view, try to put JSP in the WEB-INF or its subdirectory, why? JSP is only used as a view component. Do not write business logic in it. For example, do not access the database. However, the JSP page can contain the display logic. Note the differences between the view model and the business model. You can use treemode to understand the differences. The business model is provided to the treemode and the treemode to the view.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.