Summary of common jsp programming techniques and jsp Programming
This example summarizes common jsp programming skills. We will share this with you for your reference. The details are as follows:
1. Remove values from the drop-down list box
There is a drop-down list box in the page, as shown below:
<Td> <select> <option value = ""> </option> <option value = "18 ~ 30 "> 18 ~ 30 years old </option> <option value = "31 ~ 40 "> 31 ~ 40 </option> </select> </td>
I want to obtain the selected value and separate the age to construct the query SQL statement. There are two methods:
1.
String[] arrs=request.getParameter("select_age").split(~);int minAge=(Interger.parseInt(arr[0]));int maxAge=(Interger.parseInt(arr[1]));
In this way, the age is separated.
2. Since we only want to construct a query SQL statement, we use
Copy codeThe Code is as follows: String age = request. getParameter ("select_age"). replaceAll ("~ "," And ");
You can. (Remember that there are two spaces on both sides of and ). The query statement is constructed as follows:
Copy codeThe Code is as follows: String SQL = "select * from table where age between" + age;
2. Total number of pages = (total number of records + number of records displayed per page-1)/number of records displayed per page
3. concatenate a string array into a string (used to construct an SQL statement when multiple checkboxes are selected for deletion)
String [] del = request. getParameterValues ("checkbox"); // obtain the selected checkboxStringBuffer 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 String constant and cannot be changed. StringBuffer is a string variable, and its objects 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) "; // age and permission are int type, and sysdate is Date type.
I hope this article will help you with jsp program design.