Share java中级之jsp impl实现删除功能,

doanpeach

New member
#JSP #Java #中级 # # # #Java 中级 jsp 实现 删除 功能 功能 删除 删除 删除 删除 删除 删除

Trong hướng dẫn này, chúng tôi sẽ học cách thực hiện chức năng xóa trong JSP.Chúng tôi sẽ sử dụng các bước sau:

1. Tạo một tệp JSP mới.
2. Xác định phần tử `<form>`.
3. Thêm `<input type =" hidden "name =" id ">` phần tử.
4. Thêm `<input type =" gửi "value =" xóa ">` phần tử.
5. Viết phần tử `<jsp: forward>`.

### 1. Tạo tệp JSP mới

Đầu tiên, chúng ta cần tạo một tệp JSP mới.Chúng ta có thể thực hiện điều này bằng cách nhấp chuột phải vào thư mục `webcontent` trong Eclipse IDE và chọn ** mới **> ** Tệp JSP **.

Trong hộp thoại ** JSP **, nhập tên sau cho tệp: `Delete.jsp`.

Nhấp vào ** Kết thúc ** để tạo tệp.

### 2. Xác định phần tử `<form>`

Tiếp theo, chúng ta cần xác định phần tử `<form>`.Phần tử `<form>` được sử dụng để tạo biểu mẫu trên trang web.

Chúng ta có thể thêm phần tử `<form>` vào tệp `Delete.jsp` bằng cách sử dụng mã sau:

`` `
<form action = "delete.jsp" meather = "post">
`` `

Thuộc tính `hành động` chỉ định URL mà biểu mẫu sẽ gửi đến.Trong trường hợp này, chúng tôi đang gửi biểu mẫu cho tệp `Delete.jsp`.

Thuộc tính `Phương thức 'chỉ định phương thức mà biểu mẫu sẽ sử dụng để gửi dữ liệu.Trong trường hợp này, chúng tôi đang sử dụng phương thức `post`.

### 3. Thêm `<input type =" hidden "name =" id ">` Phần tử

Tiếp theo, chúng ta cần thêm `<input type =" hidden "name =" id ">` phần tử.Phần tử `<input type =" hidden ">` được sử dụng để tạo trường đầu vào ẩn.

Chúng ta có thể thêm phần tử `<input type =" hidden ">` vào tệp `delete.jsp` bằng cách sử dụng mã sau:

`` `
<input type = "hidden" name = "id" value = "$ {param.id}">
`` `

Thuộc tính `name` chỉ định tên của trường đầu vào.Trong trường hợp này, chúng tôi đang sử dụng tên `id`.

Thuộc tính `value` chỉ định giá trị của trường đầu vào.Trong trường hợp này, chúng tôi đang sử dụng giá trị của tham số `id`.

### 4. Thêm `<input type =" gửi "value =" xóa ">` phần tử

Tiếp theo, chúng ta cần thêm `<input type =" gửi "value =" xóa ">` phần tử.Phần tử `<input type =" gửi ">` được sử dụng để tạo nút gửi.

Chúng ta có thể thêm phần tử `<input type =" gửi ">` vào tệp `Delete.jsp` bằng cách sử dụng mã sau:

`` `
<input type = "gửi" value = "xóa">>
`` `

Thuộc tính `value` Chỉ định văn bản sẽ được hiển thị trên nút Gửi.Trong trường hợp này, chúng tôi đang sử dụng văn bản `Delete`.

### 5. Viết `<jsp: forward>` Phần tử

Cuối cùng, chúng ta cần viết phần tử `<jsp: forward>`.Phần tử `<jsp: forward>` được sử dụng để chuyển tiếp yêu cầu sang tệp JSP khác.

Chúng ta có thể thêm phần tử `<jsp: forward>` vào tệp `Delete.jsp` bằng cách sử dụng mã sau:

`` `
<jsp: trang chuyển tiếp = "xác nhận-delete.jsp">
`` `

Thuộc tính `page` Chỉ định tệp JSP mà yêu cầu sẽ được chuyển tiếp đến.Trong trường hợp này, chúng tôi đang chuyển tiếp yêu cầu đến tệp `xác nhận delete.jsp`.

### Mã hoàn chỉnh

Đây là mã hoàn chỉnh cho tệp `Delete.jsp`:

`` `
<v

<Html>
<Đầu>
<Title> Xóa </Tiêu đề>
</head>
<Body>
=======================================
#JSP #Java #中级 #删除 #功能 ## Java中级之JSP实现删除功能

In this tutorial, we will learn how to implement a delete function in JSP. We will use the following steps:

1. Create a new JSP file.
2. Define the `<form>` element.
3. Add the `<input type="hidden" name="id">` element.
4. Add the `<input type="submit" value="Delete">` element.
5. Write the `<jsp:forward>` element.

### 1. Create a new JSP file

First, we need to create a new JSP file. We can do this by right-clicking on the `WebContent` folder in the Eclipse IDE and selecting **New** > **JSP File**.

In the **JSP File** dialog box, enter the following name for the file: `delete.jsp`.

Click **Finish** to create the file.

### 2. Define the `<form>` element

Next, we need to define the `<form>` element. The `<form>` element is used to create a form on a web page.

We can add the `<form>` element to the `delete.jsp` file by using the following code:

```
<form action="delete.jsp" method="post">
```

The `action` attribute specifies the URL that the form will submit to. In this case, we are submitting the form to the `delete.jsp` file.

The `method` attribute specifies the method that the form will use to submit data. In this case, we are using the `post` method.

### 3. Add the `<input type="hidden" name="id">` element

Next, we need to add the `<input type="hidden" name="id">` element. The `<input type="hidden">` element is used to create a hidden input field.

We can add the `<input type="hidden">` element to the `delete.jsp` file by using the following code:

```
<input type="hidden" name="id" value="${param.id}">
```

The `name` attribute specifies the name of the input field. In this case, we are using the name `id`.

The `value` attribute specifies the value of the input field. In this case, we are using the value of the `id` parameter.

### 4. Add the `<input type="submit" value="Delete">` element

Next, we need to add the `<input type="submit" value="Delete">` element. The `<input type="submit">` element is used to create a submit button.

We can add the `<input type="submit">` element to the `delete.jsp` file by using the following code:

```
<input type="submit" value="Delete">
```

The `value` attribute specifies the text that will be displayed on the submit button. In this case, we are using the text `Delete`.

### 5. Write the `<jsp:forward>` element

Finally, we need to write the `<jsp:forward>` element. The `<jsp:forward>` element is used to forward a request to another JSP file.

We can add the `<jsp:forward>` element to the `delete.jsp` file by using the following code:

```
<jsp:forward page="confirm-delete.jsp">
```

The `page` attribute specifies the JSP file that the request will be forwarded to. In this case, we are forwarding the request to the `confirm-delete.jsp` file.

### Complete code

Here is the complete code for the `delete.jsp` file:

```
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<html>
<head>
<title>Delete</title>
</head>
<body>
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top