lsp66

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

对a3表进行创建
index.jsp‌
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

信息提供者及联系人信息表

信息提供者及联系人信息表

‌styles.css‌

body {
font-family: Arial, sans-serif;
margin: 40px;
}

h1 {
color: #333;
}

.form-group {
margin-bottom: 15px;
}

label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}

input[type="text"],
input[type="tel"],
select {
width: 100%;
padding: 8px;
box-sizing: border-box;
}

button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
2. 后台技术:JavaBean + Servlet
‌InfoProvider.java‌

java
Copy Code
public class InfoProvider {
private String infoProviderName;
private int relationship;
private String contactName;
private String contactPhone;

// Getters and Setters
public String getInfoProviderName() {
    return infoProviderName;
}

public void setInfoProviderName(String infoProviderName) {
    this.infoProviderName = infoProviderName;
}

public int getRelationship() {
    return relationship;
}

public void setRelationship(int relationship) {
    this.relationship = relationship;
}

public String getContactName() {
    return contactName;
}

public void setContactName(String contactName) {
    this.contactName = contactName;
}

public String getContactPhone() {
    return contactPhone;
}

public void setContactPhone(String contactPhone) {
    this.contactPhone = contactPhone;
}

}
‌InfoProviderServlet.java‌
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@WebServlet("/submitInfo")
public class InfoProviderServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    InfoProvider infoProvider = new InfoProvider();
    infoProvider.setInfoProviderName(request.getParameter("infoProviderName"));
    infoProvider.setRelationship(Integer.parseInt(request.getParameter("relationship")));
    infoProvider.setContactName(request.getParameter("contactName"));
    infoProvider.setContactPhone(request.getParameter("contactPhone"));

    try {
        // Database connection
        String url = "jdbc:oracle:thin:@//localhost:1521/xe";
        String user = "your_username";
        String password = "your_password";
        Connection conn = DriverManager.getConnection(url, user, password);

        String sql = "INSERT INTO info_providers (info_provider_name, relationship, contact_name, contact_phone) VALUES (?, ?, ?, ?)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, infoProvider.getInfoProviderName());
        pstmt.setInt(2, infoProvider.getRelationship());
        pstmt.setString(3, infoProvider.getContactName());
        pstmt.setString(4, infoProvider.getContactPhone());
        pstmt.executeUpdate();
        conn.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    response.sendRedirect("index.jsp");
}

}

posted on 2025-02-20 18:18  李世鹏66  阅读(11)  评论(0)    收藏  举报