A summary of common techniques for JSP programming _jsp programming

Source: Internet
Author: User
Tags constant stringbuffer

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.

Related Article

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.