This article summarizes the common techniques of JSP programming. Share to everyone for your reference, specific as follows:
A, detach the value in the Drop-down list box
There is a Drop-down list box in the page, as follows:
<td><select >
<option value= "" ></option>
<option value= "18~30" >18~30 years old </ option>
<option value= "31~40" >31~40 age </option>
</select></td>
I want to get the selected values and isolate the age to construct the SQL of the query, with the following two methods
1.
String[] Arrs=request.getparameter ("Select_age"). Split (~);
int minage= (Interger.parseint (arr[0]));
int maxage= (Interger.parseint (arr[1]));
This separates the ages.
2. Since we just want to construct a query for SQL, then we directly use
Copy Code code as follows:
String age=request.getparameter ("Select_age"). ReplaceAll ("~", "and");
Can. (Remember that there are two spaces on both sides). This constructs the query statement:
Copy Code code as follows:
String sql= "select * from table where age between" +age;
Total number of pages = (Total records + number of records displayed per page-1)/number of records displayed per page
Third, concatenation of a string array into a string (used to construct the SQL statement when multiple checkbox is selected for deletion)
String[] Del=request.getparametervalues ("checkbox");//Get the selected checkbox
stringbuffer inparams=new stringbuffer ();
Inparams.append (Del[0]);
for (int i=1;i<del.length;i++)
{
inparams.append ("', '");
Inparams.append (Del[i]);
String str_del=inparams.tostring ();
String sql= "Delete from T_redomanage where userName in ('" +str_del+ ")";
Note: The string class is a literal constant and is a constant that cannot be changed. While StringBuffer is a string variable, its object can be expanded and modified.
Iv. <input type= "button" value= "Delete selected" >
String sql= "insert into table (username,password,age,sex,phone,email,permission,registerdata)" + "VALUES ('" +username + "', '" +password+ "," "+age+" ', ' "+sex+", "" +phone+ "," "+email+" ', ' 0 ', sysdate) ";
Where the age and permission are int and the sysdate is the date type.
I hope this article will help you with JSP program design.