Summary of common skills in jsp programming
- 2021-11-01 04:17:04
- OfStack
This paper summarizes the common skills of jsp programming with examples. Share it for your reference, as follows:
1. Separate the values in the drop-down list box
There is a drop-down list box on the page, as follows:
<td><select >
<option value=""></option>
<option value="18~30">18~30 Years old </option>
<option value="31~40">31~40 Years old </option>
</select></td>
I want to get the selected value and separate the age to construct the sql of the query in the following two ways
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 just want to construct an sql for a query, we use the
String age=request.getParameter("select_age").replaceAll("~"," and ");
That's enough. (Remember that there are two spaces on either side of and). Construct the query statement as follows:
String sql="select * from table where age between"+age;
2. Total pages = (total records + records displayed per page-1)/records displayed per page
3. Splice an array of strings into a string (used to construct an sql statement when multiple checkbox are 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 string constant and is an immutable constant. StringBuffer is a string variable, and its objects can be extended and modified.
4. < 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)";
// Among them age And permission For int Type, sysdate For Date Type.
I hope this article is helpful to everyone's jsp programming.