JSP simple exercise-EL get form data, jsp-el get form

Source: Internet
Author: User

JSP simple exercise-EL get form data, jsp-el get form

Enter the user name and password:

<% @ Page language = "java" contentType = "text/html; charset = gb2312" %> <script type = "text/javascript"> function on_submit () {if (form1.username. value = "") {alert ("user name cannot be blank! "); // Automatically switch the focus to the username input box form1.username. focus (); return false;} if (form1.password. value = "") {alert ("the password cannot be blank! "); // Automatically switch the focus to the password input box form1.password. focus (); return false ;}} </script> Display the data in the received form:

<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> 




The method for obtaining form data in JSP, listing and explaining for more than 2 minutes

First:
There is an input box in the form tag
<Input type = "text" name = "name"/>
The backend uses String name = request. getParameter ("name"); to obtain the value of the input box.

Second:
Url-based value transfer method
<Form action = "login. do? Name = value "method =" post ">;
<A href = "login. do? Name = value "> </a>
Generally, a button or hyperlink is used to submit a form, or the input box is not in form.

In jsp, how does one read the data entered in the form when the form is not submitted?

You can use var nameElement = document. getElementById ("name") to obtain the tag object of the page,
Var nameValue = nameElement. value to obtain the value.
For example:
<% @ Page language = "java" contentType = "text/html; charset = GBK"
PageEncoding = "GBK" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = ISO-8859-1">
<Title> Insert title here </title>

<Script type = "text/javascript">

// Display input information
Function viewInfo (){
// Obtain the value of the object whose Id is "name"
Var nameValue = document. getElementById ("name"). value;
// Obtain the value of the object whose Id is "age"
Var ageValue = document. getElementById ("age"). value;
Var message = "";
If (nameValue = null | nameValue = ""){
Message + = "no name entered ."
} Else {
Message + = "name:" + nameValue;
}

If (ageValue = null | ageValue = ""){
Message + = "no age entered ."
} Else {
Message + = "Age:" + ageValue;
}
Alert (message );
}
</Script>

</Head>
<Body>
<Form>
<Br> name: <input type = "text" id = "name">
<Br> Age: <input type = "text" id =... remaining full text>

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.