Summary of common jsp programming techniques and jsp Programming

Source: Internet
Author: User

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.

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.