<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%
    String college = request.getParameter("college");
    if (college != null && !college.isEmpty()) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "SchoolST", "123456");
            String sql = "SELECT * FROM teachers WHERE college = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, college);
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                out.println("<option value='" + rs.getInt("teacher_id") + "'>" + rs.getString("name") + "</option>");
            }
            rs.close();
            pstmt.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
%>