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>