Relationship between JSP and JavaBean

Source: Internet
Author: User
You Can Use Javabean to package functions, processing, values, database access, and any other objects that can be created using Java code, other developers can use these objects through internal JSP pages, Servlets, other JavaBean, applet or applications. You can think that JavaBean provides a copy and paste function anytime, anywhere, without worrying about any changes. JavaBean can be divided into two types: one is a an with a user interface (ui, user interface); the other is that there is no user interface, mainly responsible for processing transactions (such as data operations, operate the database. JSP usually accesses the latter type of JavaBean. JavaScript scripts can be used in any Web language. They are mainly special effects and used in browser development. JSP is mainly a Java Development Technology Applied to pages, that is, Java code or labels are added to HTML pages. Javabean is a number of entity classes, generally used in model layer repost address: http://blog.163.com/hgj_online/blog/static/476742432007112610135845/2. Form onsubmit () Problem

In the past, when writing an onsubmit () script for a form (from) in the project, it was often necessary to verify the validity of the data in the form. Therefore, the statement <form action = "/admin/adduser. do "method =" Post "onsubmit =" validateform (); ">, tries to return false in validateform () to prevent form submission. In fact, even if the return false form is still submitted. Later I found that onsubmit = "Return validateform ()" had no problem, and I didn't think much about it, so I continued to do other things.

Today, I have read an article to give a clear explanation:

 

As we all know, adding onsubmit = "Return false;" to a form can prevent form submission.

The following is a simple piece of code:

Java code:

<Form
Action = "index. jsp" method = "Post" onsubmit = "submittest ();">

<Input value = "www">

<Input type = "Submit" value = "Submit">

</Form>

<Script
Language = "JavaScript">

<! --

Function submittest (){

// Some logical judgments

Return false;

}

// -->

</SCRIPT>

You can determine whether the form is submitted by clicking the submit button as described above?

If the answer is yes, you don't have to look down.

If the answer is no, it is incorrect. The actual situation is that the form is submitted normally. If you do not want it to be submitted, you should

Java code:

<Form
Action = "index. jsp" method = "Post" onsubmit = "submittest ();">

Change

Java code:

<Form
Action = "index. jsp" method = "Post" onsubmit = "Return submittest ();">

Why?

The onsubmit attribute is like a method name of the <form> HTML object. Its value (a string) is its method body. By default, true is returned;

Like java, you can write any number of statements in the method body, including built-in functions and custom functions, such

Java code:

Onsubmit ="

 
Alert ('hahaha'); // built-in functions

Submittest (); // User-Defined Function

Alert (this. tagname); // This keyword is used.

... (Any number of statements)

Return false;

"

It is equivalent

Java code:

Form. Prototype. onsubmit
= Function (){

Alert ('hahaha'); // built-in functions

Submittest (); // User-Defined Function

Alert (this. tagname); // This keyword is used.

... (Any number of statements)

 
Return false;

};

In this case, you overwrite (override) the default method (true is returned by default)

You have noticed that the keyword "this" can be used in the method body, which represents the object instance of <form>.

After such analysis, it is difficult to understand the above situation:

Java code:

<Form
Action = "index. jsp" method = "Post" onsubmit = "submittest ();">

Write the override method as follows:

Java code:

Form. Prototype. onsubmit
= Function (){

Submittest ();

};

Although submittest () returns false, we only execute this function and do not process the result. While

Java code:

<Form
Action = "index. jsp" method = "Post" onsubmit = "Return submittest ();">

The effects of the override method are as follows:

Java code:

Form. Prototype. onsubmit
= Function (){

Return submittest ();

};

In this way, we use its return value to achieve the expected results.

In this way, I think it will be much more impressive and it will not be easy to make mistakes.

Conclusion:

We can use the way of thinking in Java to simulate similar situations in JavaScript (prototype-Based Object-Oriented Technology in JavaScript does ), however, after all, they are essentially different. For example, Java is strongly typed and has strict syntax restrictions, while Javascript is loose. As shown in the preceding method:

Java code:

Form. Prototype. onsubmit
= Function (){

};

There can be both a return value and no return value, which is not acceptable in Java. After all, Java cannot rely on different return values to overload the method, the reload in Javascript is much loose.

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.