transform_zh_to_utf8.bat

本文介绍了一个批处理脚本,该脚本用于将中文编码的属性文件转换为UTF-8编码。通过使用native2ascii命令,脚本可以实现从特定源文件到目标文件的编码转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@echo off
echo 批处理文件命令要写成一行,并且不能将批处理文件命名为:native2ascii.bat

set insrc=test_zh.properties
set revertsrc=test_utf8.properties

echo --------中文编码文件: %insrc%
echo --------UTF-8编码文件: %revertsrc%

rem ------------------注释----------------------
rem if exist %revertsrc% del %revertsrc%
rem --------------------------------------------

if exist %insrc% native2ascii -encoding UTF-8 %insrc% %revertsrc%

pause
HTML 文档# 电路电荷定向移动动画 (HTML5 Canvas实现) 以下是一个使用HTML5 Canvas创建电路中电荷定向移动动画的完整代码: ```html <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>电路电荷定向移动动画</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f0f0f0; font-family: Arial, sans-serif; } canvas { background-color: white; box-shadow: 0 0 10px rgba(0,0,0,0.1); } .controls { position: absolute; top: 20px; left: 20px; background: rgba(255,255,255,0.8); padding: 10px; border-radius: 5px; } </style> </head> <body> <div class="controls"> <label for="voltage">电压 (V): </label> <input type="range" id="voltage" min="1" max="10" value="5" step="1"> <span id="voltageValue">5</span> </div> <canvas id="circuitCanvas" width="800" height="400"></canvas> <script> const canvas = document.getElementById('circuitCanvas'); const ctx = canvas.getContext('2d'); const voltageSlider = document.getElementById('voltage'); const voltageValue = document.getElementById('voltageValue'); // 电路参数 const circuit = { startX: 100, startY: 200, width: 600, height: 100, resistorX: 450, resistorWidth: 30, batteryWidth: 40, electronRadius: 4, electronCount: 50, speed: 1, voltage: 5 }; // 电子数组 let electrons = []; // 初始化电子 function initElectrons() { electrons = []; const segmentLength = circuit.width / circuit.electronCount; for (let i = 0; i < circuit.electronCount; i++) { // 在导线路径上均匀分布电子 let x, y; if (i * segmentLength < circuit.resistorX - circuit.startX - circuit.resistorWidth/2) { // 电阻前段 x = circuit.startX + i * segmentLength; y = circuit.startY; } else if (i * segmentLength < circuit.resistorX - circuit.startX + circuit.resistorWidth/2) { // 电阻段 x = circuit.resistorX; y = circuit.startY + ((i * segmentLength - (circuit.resistorX - circuit.startX - circuit.resistorWidth/2)) / circuit.resistorWidth - 0.5) * circuit.height; } else { // 电阻后段 x = circuit.startX + i * segmentLength; y = circuit.startY + circuit.height; } electrons.push({ x: x, y: y, speed: circuit.speed * (circuit.voltage / 5), // 速度与电压成正比 inResistor: false }); } } // 绘制电路 function drawCircuit() { ctx.clearRect(0, 0, canvas.width, canvas.height); // 绘制导线 ctx.beginPath(); ctx.moveTo(circuit.startX, circuit.startY); // 导线到电阻前 ctx.lineTo(circuit.resistorX - circuit.resistorWidth/2, circuit.startY); // 电阻符号 ctx.moveTo(circuit.resistorX - circuit.resistorWidth/2, circuit.startY); ctx.lineTo(circuit.resistorX - circuit.resistorWidth/2, circuit.startY + circuit.height); ctx.moveTo(circuit.resistorX + circuit.resistorWidth/2, circuit.startY); ctx.lineTo(circuit.resistorX + circuit.resistorWidth/2, circuit.startY + circuit.height); // 电阻后导线 ctx.moveTo(circuit.resistorX + circuit.resistorWidth/2, circuit.startY + circuit.height); ctx.lineTo(circuit.startX + circuit.width, circuit.startY + circuit.height); // 闭合回路 ctx.lineTo(circuit.startX + circuit.width, circuit.startY); ctx.lineTo(circuit.startX, circuit.startY); ctx.strokeStyle = '#333'; ctx.lineWidth = 2; ctx.stroke(); // 绘制电池 drawBattery(circuit.startX - circuit.batteryWidth, circuit.startY + circuit.height/2 - 20); // 绘制电子 drawElectrons(); // 绘制标签 drawLabels(); } // 绘制电池 function drawBattery(x, y) { // 电池主体 ctx.fillStyle = '#ddd'; ctx.fillRect(x, y, circuit.batteryWidth, 40); // 电池正极 ctx.fillStyle = 'red'; ctx.fillRect(x + circuit.batteryWidth - 8, y + 10, 5, 20); // 电池负极 ctx.fillStyle = 'blue'; ctx.fillRect(x + 3, y + 10, 5, 20); // 电池标记 ctx.fillStyle = 'black'; ctx.font = '12px Arial'; ctx.fillText('+', x + circuit.batteryWidth - 10, y + 15); ctx.fillText('-', x + 5, y + 15); } // 绘制电子 function drawElectrons() { electrons.forEach(electron => { ctx.beginPath(); ctx.arc(electron.x, electron.y, circuit.electronRadius, 0, Math.PI * 2); ctx.fillStyle = 'blue'; ctx.fill(); }); } // 绘制标签 function drawLabels() { ctx.fillStyle = 'black'; ctx.font = '16px Arial'; // 电子流方向 ctx.fillText('电子流方向', circuit.startX + circuit.width/2 - 50, circuit.startY - 20); drawArrow(circuit.startX + circuit.width/2, circuit.startY - 25, -30, 0, 'blue'); // 传统电流方向 ctx.fillText('传统电流方向', circuit.startX + circuit.width/2 - 60, circuit.startY + circuit.height + 40); drawArrow(circuit.startX + circuit.width/2, circuit.startY + circuit.height + 35, 30, 0, 'red'); // 电压显示 ctx.fillText(`电压: ${circuit.voltage}V`, circuit.startX - circuit.batteryWidth, circuit.startY + circuit.height/2 + 50); // 电阻标签 ctx.fillText('电阻', circuit.resistorX - 15, circuit.startY + circuit.height/2 + 30); } // 绘制箭头 function drawArrow(x, y, dx, dy, color) { const headLength = 10; const angle = Math.atan2(dy, dx); ctx.strokeStyle = color; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + dx, y + dy); ctx.stroke(); // 箭头 ctx.beginPath(); ctx.moveTo(x + dx, y + dy); ctx.lineTo(x + dx - headLength * Math.cos(angle - Math.PI/6), y + dy - headLength * Math.sin(angle - Math.PI/6)); ctx.moveTo(x + dx, y + dy); ctx.lineTo(x + dx - headLength * Math.cos(angle + Math.PI/6), y + dy - headLength * Math.sin(angle + Math.PI/6)); ctx.stroke(); } // 更新电子位置 function updateElectrons() { electrons.forEach(electron => { // 确定电子所在的电路段 if (electron.x < circuit.resistorX - circuit.resistorWidth/2) { // 电阻前段 - 水平向右移动 electron.x += electron.speed; electron.y = circuit.startY; electron.inResistor = false; // 如果电子到达电阻前边界,进入电阻段 if (electron.x >= circuit.resistorX - circuit.resistorWidth/2) { electron.x = circuit.resistorX - circuit.resistorWidth/2; } } else if (electron.x >= circuit.resistorX - circuit.resistorWidth/2 && electron.x <= circuit.resistorX + circuit.resistorWidth/2) { // 电阻段 - 垂直向下移动(速度减半) const progress = (electron.y - circuit.startY) / circuit.height; electron.y += electron.speed * 0.5; electron.x = circuit.resistorX; electron.inResistor = true; // 如果电子通过电阻,进入电阻后段 if (electron.y >= circuit.startY + circuit.height) { electron.y = circuit.startY + circuit.height; } } else { // 电阻后段 - 水平向左移动 electron.x -= electron.speed; electron.y = circuit.startY + circuit.height; electron.inResistor = false; // 如果电子到达左边界,回到电池负极 if (electron.x <= circuit.startX) { electron.x = circuit.startX + circuit.width; electron.y = circuit.startY; } } }); } // 动画循环 function animate() { updateElectrons(); drawCircuit(); requestAnimationFrame(animate); } // 初始化 initElectrons(); animate(); // 电压控制 voltageSlider.addEventListener('input', function() { circuit.voltage = parseInt(this.value); voltageValue.textContent = circuit.voltage; // 更新电子速度 electrons.forEach(electron => { electron.speed = circuit.speed * (circuit.voltage / 5); }); }); </script> </body> </html> ``` ## 动画功能说明 1. **电路可视化**: - 显示完整的闭合电路,包括电池、导线和电阻 - 电池标有正负极(+/-) 2. **电荷运动**: - 蓝色圆点代表电子,沿电路移动 - 电子从电池负极出发,流向正极 - 在电阻处移动速度减慢 3. **交互控制**: - 滑动条可调节电压(1-10V) - 电压越高,电子移动速度越快 4. **标注信息**: - 显示电子流方向(蓝色箭头) - 显示传统电流方向(红色箭头,与电子流相反) - 显示当前电压值 - 电阻位置明确标注 ## 如何使用 1. 将代码复制到一个HTML文件中 2. 在浏览器中打开该文件 3. 使用滑动条调节电压,观察电子速度变化 您可以根据需要修改电路尺寸、电子数量或颜色等参数来自定义动画。
07-15
contactList.jsp:<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title>${isBlacklist ? '黑名单' : '联系人列表'}</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet"> <style> :root { --primary-color: #4361ee; --secondary-color: #3f37c9; --success-color: #4cc9f0; --danger-color: #f72585; --warning-color: #f8961e; --light-color: #f8f9fa; --dark-color: #212529; } body { background-color: #f5f7fa; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .container { max-width: 1400px; padding: 20px; } .header-section { background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); color: white; border-radius: 15px; padding: 2rem; margin-bottom: 2rem; box-shadow: 0 10px 20px rgba(67, 97, 238, 0.15); } .page-title { font-weight: 700; margin: 0; display: flex; align-items: center; } .page-title i { font-size: 2rem; margin-right: 1rem; } .action-buttons .btn { border-radius: 50px; padding: 0.5rem 1.5rem; font-weight: 500; margin-left: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); transition: all 0.3s ease; } .action-buttons .btn:hover { transform: translateY(-2px); box-shadow: 0 7px 14px rgba(0, 0, 0, 0.15); } .nav-tabs { border-bottom: none; margin: 1.5rem 0; } .nav-tabs .nav-link { border: none; color: #6c757d; font-weight: 500; padding: 0.75rem 1.5rem; border-radius: 50px; margin-right: 0.5rem; transition: all 0.3s ease; } .nav-tabs .nav-link.active { background-color: var(--primary-color); color: white; box-shadow: 0 4px 6px rgba(67, 97, 238, 0.3); } .nav-tabs .nav-link:not(.active):hover { color: var(--primary-color); background-color: rgba(67, 97, 238, 0.1); } .search-box { background: white; border-radius: 50px; padding: 0.5rem; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); } .search-box input { border: none; border-radius: 50px 0 0 50px; padding: 0.75rem 1.5rem; } .search-box input:focus { box-shadow: none; } .search-box button { border-radius: 0 50px 50px 0; background-color: var(--primary-color); color: white; border: none; padding: 0.75rem 1.5rem; transition: all 0.3s ease; } .search-box button:hover { background-color: var(--secondary-color); } .contact-card { background: white; border-radius: 15px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05); transition: all 0.3s ease; margin-bottom: 1.5rem; overflow: hidden; } .contact-card:hover { transform: translateY(-5px); box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1); } .contact-avatar { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; border: 3px solid white; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); } .contact-info { padding: 1.5rem; } .contact-name { font-weight: 600; color: var(--dark-color); margin-bottom: 0.5rem; } .contact-phone { color: #6c757d; font-size: 0.9rem; } .status-badge { font-size: 0.8rem; padding: 0.35rem 0.75rem; border-radius: 50px; font-weight: 500; } .action-btn { min-width: 100px; border-radius: 50px; font-size: 0.85rem; font-weight: 600; padding: 0.5rem 1rem; margin: 0.25rem; transition: all 0.3s ease; } .action-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1); } .pagination { margin-top: 3rem; justify-content: center; } .page-item .page-link { border-radius: 50px !important; margin: 0 0.25rem; border: none; color: var(--dark-color); font-weight: 500; min-width: 40px; text-align: center; } .page-item.active .page-link { background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)); color: white; box-shadow: 0 4px 6px rgba(67, 97, 238, 0.3); } .no-contacts { text-align: center; padding: 3rem; color: #6c757d; } .no-contacts i { font-size: 3rem; color: #dee2e6; margin-bottom: 1rem; } /* 天气预报样式 */ .weather-widget { background: linear-gradient(135deg, #1e3c72, #2a5298); color: white; border-radius: 15px; padding: 2rem; margin-bottom: 2rem; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15); position: relative; overflow: hidden; } .weather-widget::before { content: ""; position: absolute; top: -50%; right: -50%; width: 200%; height: 200%; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%); z-index: 0; } .weather-content { position: relative; z-index: 1; } .weather-title { font-weight: 700; margin: 0; display: flex; align-items: center; font-size: 1.5rem; } .weather-title i { font-size: 1.8rem; margin-right: 1rem; } .weather-details { display: flex; align-items: center; justify-content: space-between; margin-top: 1.5rem; } .weather-info { flex: 1; } .weather-city { font-size: 1.8rem; font-weight: 600; margin-bottom: 0.5rem; } .weather-desc { font-size: 1.2rem; opacity: 0.9; margin-bottom: 0.5rem; text-transform: capitalize; } .weather-temp { font-size: 3rem; font-weight: 700; margin: 0; line-height: 1; } .weather-icon-container { width: 100px; height: 100px; display: flex; align-items: center; justify-content: center; } .weather-icon { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3)); } .weather-extra { display: flex; justify-content: space-between; margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid rgba(255, 255, 255, 0.2); } .weather-extra-item { text-align: center; flex: 1; } .weather-extra-label { font-size: 0.9rem; opacity: 0.8; margin-bottom: 0.3rem; } .weather-extra-value { font-size: 1.2rem; font-weight: 600; } /* 天气动画 */ @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } .weather-animate { animation: fadeIn 0.5s ease-out forwards; } /* 移动端特定样式 */ @media (max-width: 768px) { .header-section { padding: 1.5rem; } .action-buttons { margin-top: 1rem; } .contact-avatar { width: 60px; height: 60px; } .action-btn { min-width: auto; padding: 0.4rem 0.8rem; font-size: 0.8rem; } .search-box input, .search-box button { padding: 0.5rem 1rem; } .nav-tabs .nav-link { padding: 0.5rem 1rem; margin-right: 0.25rem; } .weather-widget { padding: 1.5rem; } .weather-temp { font-size: 2rem; } .weather-city { font-size: 1.2rem; } } /* 触摸友好元素 */ .btn, .form-control, .nav-link, .page-link { touch-action: manipulation; } </style> </head> <body> <div class="container"> <div class="header-section"> <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center"> <h1 class="page-title"> <i class="bi bi-people-fill"></i> ${isBlacklist ? '黑名单管理' : '联系人中心'} </h1> <div class="action-buttons mt-3 mt-md-0"> <a href="${pageContext.request.contextPath}/contact?action=add" class="btn btn-light"> <i class="bi bi-person-plus"></i> 新增联系人 </a> <a href="${pageContext.request.contextPath}/matter" class="btn btn-outline-light"> <i class="bi bi-calendar2-event"></i> 查看事项 </a> </div> </div> </div> <!-- 天气预报区域 --> <div class="weather-widget"> <div class="weather-content"> <h2 class="weather-title"> <i class="bi bi-geo-alt"></i> 实时天气 </h2> <div class="weather-details"> <div class="weather-info"> <div class="weather-city" id="weatherCity">唐山</div> <div class="weather-desc" id="weatherDesc">--</div> <div class="weather-temp" id="weatherTemp">--°C</div> </div> <div class="weather-icon-container"> <img id="weatherIcon" class="weather-icon" src="https://openweathermap.org/img/wn/${data.weather.icon}@2x.png" alt="天气图标"> </div> </div> </div> </div> <div class="weather-extra"> <div class="weather-extra-item"> <div class="weather-extra-label">湿度</div> <div class="weather-extra-value" id="weatherHumidity">--%</div> </div> <div class="weather-extra-item"> <div class="weather-extra-label">风速</div> <div class="weather-extra-value" id="weatherWind">-- m/s</div> </div> <div class="weather-extra-item"> <div class="weather-extra-label">气压</div> <div class="weather-extra-value" id="weatherPressure">-- hPa</div> </div> </div> <ul class="nav nav-tabs"> <li class="nav-item"> <a class="nav-link ${not isBlacklist ? 'active' : ''}" href="${pageContext.request.contextPath}/contact">正常联系人</a> </li> <li class="nav-item"> <a class="nav-link ${isBlacklist ? 'active' : ''}" href="${pageContext.request.contextPath}/contact?action=blacklist">黑名单</a> </li> </ul> <!-- 筛选区域 --> <div class="filter-section"> <h5 class="filter-title">筛选条件</h5> <form class="row g-3" method="get" action="${pageContext.request.contextPath}/contact"> <input type="hidden" name="action" value="${isBlacklist ? 'blacklist' : ''}"> <div class="col-md-6"> <div class="input-group"> <input type="text" class="form-control" name="search" placeholder="搜索姓名/电话" value="${param.search}" aria-label="Search"> <button class="btn btn-primary" type="submit"> <i class="bi bi-search"></i> 搜索了一个 </button> </div> </div> <div class="col-md-4"> <select class="form-select" name="gender" onchange="this.form.submit()"> <option value="">所有性别</option> <option value="男" ${param.gender == '男' ? 'selected' : ''}>男</option> <option value="女" ${param.gender == '女' ? 'selected' : ''}>女</option> </select> </div> <div class="col-md-2"> <a href="${pageContext.request.contextPath}/contact${isBlacklist ? '?action=blacklist' : ''}" class="btn btn-outline-secondary w-100"> <i class="bi bi-arrow-counterclockwise"></i> 重置 </a> </div> </form> </div> <c:if test="${empty contacts}"> <div class="card contact-card"> <div class="no-contacts"> <i class="bi bi-people"></i> <h4>暂无联系人数据</h4> <p>点击"新增联系人"按钮添加您的第一个联系人</p> </div> </div> </c:if> <div class="row"> <c:forEach var="contact" items="${contacts}"> <div class="col-md-6 col-lg-4"> <div class="card contact-card"> <div class="contact-info"> <div class="d-flex align-items-center"> <img src="${pageContext.request.contextPath}/upload/${DBUtil.getContactPic(contact.ctId)}" class="contact-avatar me-3" onerror="this.onerror=null; this.src='${pageContext.request.contextPath}/images/default-avatar.png'"> <div> <h5 class="contact-name mb-1"> ${contact.ctName} <c:if test="${contact.ctDelete == 1}"> <span class="badge bg-danger ms-2">已屏蔽</span> </c:if> </h5> <p class="contact-phone mb-1"> <i class="bi bi-telephone"></i> ${contact.ctPhone} </p> <span class="status-badge bg-${isBlacklist ? 'danger' : 'success'}"> ${isBlacklist ? '黑名单' : '正常'} </span> </div> </div> <div class="d-flex flex-wrap justify-content-between mt-3"> <a href="${pageContext.request.contextPath}/contact?action=detail&ctId=${contact.ctId}" class="btn btn-primary action-btn"> <i class="bi bi-eye"></i> 详情 </a> <a href="${pageContext.request.contextPath}/matter?ctId=${contact.ctId}" class="btn btn-warning action-btn"> <i class="bi bi-list-check"></i> 事项 </a> <c:choose> <c:when test="${isBlacklist}"> <a href="${pageContext.request.contextPath}/contact?action=blacklist&type=remove&ctId=${contact.ctId}" class="btn btn-success action-btn" onclick="return confirm('确定要恢复此联系人吗?')"> <i class="bi bi-arrow-counterclockwise"></i> 恢复 </a> </c:when> <c:otherwise> <c:if test="${contact.ctDelete == 0}"> <a href="${pageContext.request.contextPath}/contact?action=blacklist&type=add&ctId=${contact.ctId}" class="btn btn-danger action-btn" onclick="return confirm('确定要加入黑名单吗?')"> <i class="bi bi-ban"></i> 屏蔽 </a> </c:if> </c:otherwise> </c:choose> </div> </div> </div> </div> </c:forEach> </div> <c:if test="${not empty contacts}"> <nav aria-label="Page navigation"> <ul class="pagination"> <c:if test="${currentPage > 1}"> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/contact?action=${isBlacklist ? 'blacklist' : ''}&page=${currentPage - 1}&search=${param.search}"> <i class="bi bi-chevron-left"></i> </a> </li> </c:if> <c:forEach begin="1" end="${totalPages}" var="i"> <li class="page-item ${i == currentPage ? 'active' : ''}"> <a class="page-link" href="${pageContext.request.contextPath}/contact?action=${isBlacklist ? 'blacklist' : ''}&page=${i}&search=${param.search}">${i}</a> </li> </c:forEach> <c:if test="${currentPage < totalPages}"> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/contact?action=${isBlacklist ? 'blacklist' : ''}&page=${currentPage + 1}&search=${param.search}"> <i class="bi bi-chevron-right"></i> </a> </li> </c:if> </ul> </nav> </c:if> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> // 获取天气数据 function getWeather() { const apiKey = "d9bd1b0c215b38f1ceba3a8b06818789"; // OpenWeatherMap API密钥 const city = "Tangshan"; // 唐山的英文名 // 获取唐山天气 fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}&units=metric&lang=zh_cn`) .then(response => { if (!response.ok) { throw new Error("网络响应错误:" + response.statusText); } return response.json(); }) .then(data => { updateWeatherUI(data); }) .catch(error => { console.error('获取天气数据失败:', error); showWeatherError(); }); } // 更新天气UI function updateWeatherUI(data) { document.getElementById('weatherTemp').textContent = `${Math.round(data.main.temp)}°C`; document.getElementById('weatherDesc').textContent = data.weather[0]?.description || "--"; document.getElementById('weatherIcon').src = `https://openweathermap.org/img/wn/${data.weather.icon}@2x.png`; document.getElementById('weatherHumidity').textContent = `${data.main.humidity}%`; document.getElementById('weatherWind').textContent = `${data.wind.speed} m/s`; document.getElementById('weatherPressure').textContent = `${data.main.pressure} hPa`; } // 显示天气错误 function showWeatherError() { document.getElementById('weatherCity').textContent = "天气数据获取失败"; document.getElementById('weatherDesc').textContent = "请检查网络连接"; document.getElementById('weatherTemp').textContent = "--°C"; document.getElementById('weatherHumidity').textContent = "--%"; document.getElementById('weatherWind').textContent = "-- m/s"; document.getElementById('weatherPressure').textContent = "-- hPa"; } // 页面加载完成后获取天气数据 document.addEventListener('DOMContentLoaded', getWeather); </script> </body> </html>控制台日志:D:\apache-tomcat-8.5.99\bin\catalina.bat run [2025-06-10 09:39:00,390] Artifact firstweb2:war: Waiting for server connection to start artifact deployment... Using CATALINA_BASE: "C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1" Using CATALINA_HOME: "D:\apache-tomcat-8.5.99" Using CATALINA_TMPDIR: "D:\apache-tomcat-8.5.99\temp" Using JRE_HOME: "D:\java" Using CLASSPATH: "D:\apache-tomcat-8.5.99\bin\bootstrap.jar;D:\apache-tomcat-8.5.99\bin\tomcat-juli.jar" Using CATALINA_OPTS: "" NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server.服务器版本: Apache Tomcat/8.5.99 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 服务器构建: Feb 14 2024 22:52:13 UTC 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 服务器版本号: 8.5.99.0 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 操作系统名称: Windows 11 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: OS.版本: 10.0 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 架构: amd64 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java 环境变量: D:\java 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: Java虚拟机版本: 18.0.2.1+1-1 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: JVM.供应商: Oracle Corporation 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_BASE: C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: CATALINA_HOME: D:\apache-tomcat-8.5.99 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: --add-opens=java.base/java.lang=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: --add-opens=java.base/java.io=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: --add-opens=java.base/java.util=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djava.util.logging.config.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1\conf\logging.properties 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcom.sun.management.jmxremote= 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcom.sun.management.jmxremote.port=1099 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcom.sun.management.jmxremote.ssl=false 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcom.sun.management.jmxremote.password.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1\jmxremote.password 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcom.sun.management.jmxremote.access.file=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1\jmxremote.access 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djava.rmi.server.hostname=127.0.0.1 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djdk.tls.ephemeralDHKeySize=2048 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dignore.endorsed.dirs= 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcatalina.base=C:\Users\DELL\AppData\Local\JetBrains\IntelliJIdea2022.2\tomcat\673dafd6-7580-4107-962c-bab19e459aa1 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Dcatalina.home=D:\apache-tomcat-8.5.99 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.VersionLoggerListener log 信息: 命令行参数: -Djava.io.tmpdir=D:\apache-tomcat-8.5.99\temp 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: 使用APR版本[1.7.4]加载了基于APR的Apache Tomcat本机库[1.2.39]。 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR功能:IPv6[true]、sendfile[true]、accept filters[false]、random[true]、UDS [{4}]。 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: APR/OpenSSL配置:useAprConnector[false],useOpenSSL[true] 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.AprLifecycleListener initializeSSL 信息: OpenSSL成功初始化 [OpenSSL 3.0.11 19 Sep 2023] 6月 10, 2025 9:39:01 下午 org.apache.coyote.AbstractProtocol init 信息: 初始化协议处理器 ["http-nio-8080"] 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.Catalina load 信息: Initialization processed in 370 ms 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.StandardService startInternal 信息: 正在启动服务[Catalina] 6月 10, 2025 9:39:01 下午 org.apache.catalina.core.StandardEngine startInternal 信息: 正在启动 Servlet 引擎:[Apache Tomcat/8.5.99] 6月 10, 2025 9:39:01 下午 org.apache.coyote.AbstractProtocol start 信息: 开始协议处理句柄["http-nio-8080"] 6月 10, 2025 9:39:01 下午 org.apache.catalina.startup.Catalina start 信息: Server startup in 82 ms Connected to server [2025-06-10 09:39:01,626] Artifact firstweb2:war: Artifact is being deployed, please wait... 6月 10, 2025 9:39:02 下午 org.apache.jasper.servlet.TldScanner scanJars 信息: 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。 ־ ʼ === ݿ === û (user_message) ϵ ˱ (contact_message) ϵ ͼƬ (contact_picture_message) ϵ (contact_matter_message) === === ־ ʼ === ݿ === û (user_message) ϵ ˱ (contact_message) ϵ ͼƬ (contact_picture_message) ϵ (contact_matter_message) === === [2025-06-10 09:39:02,537] Artifact firstweb2:war: Artifact is deployed successfully [2025-06-10 09:39:02,537] Artifact firstweb2:war: Deploy took 911 milliseconds === Ϣ === URL: http://localhost:8080/firstweb2_war/ 󷽷 : GET : null û ỰID: === Ϣ === URL: http://localhost:8080/firstweb2_war/ 󷽷 : GET : null û ỰID: === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 2ms === === === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 3ms === === === Ϣ === URL: http://localhost:8080/firstweb2_war/login 󷽷 : POST : null û ỰID: === Ϣ === URL: http://localhost:8080/firstweb2_war/login 󷽷 : POST : null û ỰID: === Ӧ Ϣ === Ӧ״̬: 302 ʱ : 29ms === === === Ӧ Ϣ === Ӧ״̬: 302 ʱ : 29ms === === === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : null û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : null û ỰID: EDB570CA9B045C3BD0946687C2639008 6月 10, 2025 9:39:11 下午 org.apache.catalina.startup.HostConfig deployDirectory 信息: 把web 应用程序部署到目录 [D:\apache-tomcat-8.5.99\webapps\manager] 6月 10, 2025 9:39:11 下午 org.apache.catalina.startup.HostConfig deployDirectory 信息: Web应用程序目录[D:\apache-tomcat-8.5.99\webapps\manager]的部署已在[153]毫秒内完成 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : action=detail&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : action=detail&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 180ms === === === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 180ms === === === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : POST : action=update&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : POST : action=update&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ӧ Ϣ === Ӧ״̬: 302 ʱ : 93ms === === === Ӧ Ϣ === Ӧ״̬: 302 ʱ : 93ms === === === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : action=detail&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : action=detail&ctId=0000000002 û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 31ms === === === Ӧ Ϣ === Ӧ״̬: 200 ʱ : 32ms === === === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : null û ỰID: EDB570CA9B045C3BD0946687C2639008 === Ϣ === URL: http://localhost:8080/firstweb2_war/contact 󷽷 : GET : null û ỰID: EDB570CA9B045C3BD0946687C2639008 还是无法查看天气情况,无法更新,请基于我的代码给出具体的解决措施和代码,代码要完完整整的,要全部的
06-11
index.html里 我在哪里添加更改 看不懂<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>智能助手 - 支持联网搜索</title> <style> /* 保持原有样式基础上添加新样式 */ .search-toggle { margin: 15px 0; display: flex; align-items: center; } .toggle-switch { position: relative; display: inline-block; width: 60px; height: 30px; } .toggle-switch input { opacity: 0; width: 0; height: 0; } .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 30px; } .slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; } input:checked + .slider { background-color: #3498db; } input:checked + .slider:before { transform: translateX(30px); } .search-info { font-size: 14px; color: #2c3e50; font-weight: 500; padding: 5px 10px; background-color: #d1ecf1; border-radius: 4px; margin-left: 10px; } .search-results { background-color: #f8f9fa; border-left: 4px solid #3498db; padding: 10px; margin: 10px 0; border-radius: 0 5px 5px 0; } .search-results a { color: #1a73e8; text-decoration: none; } .search-results a:hover { text-decoration: underline; } .typing-indicator { display: flex; align-items: center; padding: 5px; } .typing-dot { width: 8px; height: 8px; background-color: #3498db; border-radius: 50%; margin: 0 3px; animation: typing 1.4s infinite; } .typing-dot:nth-child(2) { animation-delay: 0.2s; } .typing-dot:nth-child(3) { animation-delay: 0.4s; } @keyframes typing { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } } </style> </head> <body> <h1>你好!我是本地大模型助手</h1> <!-- 联网搜索开关 --> <div class="search-toggle"> <label class="toggle-switch"> <input type="checkbox" id="webSearchToggle" checked> <span class="slider"></span> </label> <label for="webSearchToggle">启用联网搜索</label> <div id="searchInfo" class="search-info">联网搜索已启用</div> </div> <div id="chat"></div> <input type="text" id="input" placeholder="输入问题..." /> <button onclick="send()">发送</button> <script> const chat = document.getElementById("chat"); const webSearchToggle = document.getElementById("webSearchToggle"); const searchInfo = document.getElementById("searchInfo"); // 监听联网搜索开关变化 webSearchToggle.addEventListener('change', function() { if (this.checked) { searchInfo.textContent = "联网搜索已启用"; appendMessage("助手", "联网搜索功能已启用,我将获取最新信息来回答你的问题", "bot"); } else { searchInfo.textContent = "联网搜索已禁用"; appendMessage("助手", "联网搜索功能已禁用,我将基于已有知识回答问题", "bot"); } }); // 修改send函数支持联网搜索 async function send() { const input = document.getElementById("input"); const msg = input.value.trim(); if (!msg) return; appendMessage("你", msg, "user"); input.value = ""; const useWebSearch = webSearchToggle.checked; if (useWebSearch) { // 显示搜索中提示 const searchingDiv = appendMessage("助手", "", "bot"); searchingDiv.innerHTML = '<strong>助手:</strong>正在搜索网络信息...'; // 显示加载动画 const typingDiv = document.createElement("div"); typingDiv.className = "typing-indicator"; typingDiv.innerHTML = ` <div class="typing-dot"></div> <div class="typing-dot"></div> <div class="typing-dot"></div> `; searchingDiv.appendChild(typingDiv); try { // 调用搜索API const searchResponse = await fetch("http://localhost:5001/search", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query: msg }) }); if (!searchResponse.ok) { throw new Error(`搜索失败: ${searchResponse.status}`); } const searchData = await searchResponse.json(); // 移除加载动画 typingDiv.remove(); // 显示搜索结果 const resultsDiv = document.createElement("div"); resultsDiv.className = "search-results"; resultsDiv.innerHTML = ` <strong>搜索到 ${searchData.results.length} 条相关信息:</strong> <ul> ${searchData.results.slice(0, 3).map(result => ` <li> <a href="${result.url}" target="_blank">${result.title}</a> <p>${result.snippet}</p> </li> `).join('')} </ul> `; searchingDiv.appendChild(resultsDiv); // 显示思考中消息 const thinkingDiv = appendMessage("助手", "正在分析搜索结果...", "bot"); // 显示加载动画 const thinkingIndicator = document.createElement("div"); thinkingIndicator.className = "typing-indicator"; thinkingIndicator.innerHTML = ` <div class="typing-dot"></div> <div class="typing-dot"></div> <div class="typing-dot"></div> `; thinkingDiv.appendChild(thinkingIndicator); // 将搜索内容作为上下文发送给大模型 const context = `用户问题: ${msg}\n\n搜索到的信息:\n${searchData.results.map(r => r.snippet).join('\n')}`; const modelResponse = await fetch("/completion", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt: context, stream: false }) }); if (!modelResponse.ok) { throw new Error(`模型请求失败: ${modelResponse.status}`); } const modelData = await modelResponse.json(); // 移除加载动画 thinkingIndicator.remove(); // 显示最终回答 appendMessage("助手", modelData.content, "bot"); } catch (error) { console.error("联网搜索失败:", error); appendMessage("助手", `联网搜索失败: ${error.message}`, "bot"); } } else { // 不使用联网搜索,直接调用大模型 const thinkingDiv = appendMessage("助手", "思考中...", "bot"); // 显示加载动画 const thinkingIndicator = document.createElement("div"); thinkingIndicator.className = "typing-indicator"; thinkingIndicator.innerHTML = ` <div class="typing-dot"></div> <div class="typing-dot"></div> <div class="typing-dot"></div> `; thinkingDiv.appendChild(thinkingIndicator); try { const response = await fetch("/completion", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt: msg, stream: false }) }); if (!response.ok) { throw new Error(`模型请求失败: ${response.status}`); } const data = await response.json(); // 移除加载动画 thinkingIndicator.remove(); appendMessage("助手", data.content, "bot"); } catch (error) { console.error("请求失败:", error); appendMessage("助手", `处理请求时出错: ${error.message}`, "bot"); } } } function appendMessage(who, text, cls) { const div = document.createElement("div"); div.className = cls; div.innerHTML = `<strong>${who}:</strong>${text}`; chat.appendChild(div); chat.scrollTop = chat.scrollHeight; return div; } // 初始消息 appendMessage("助手", "你好!我是本地大模型助手。启用联网搜索后,我可以获取最新信息来回答你的问题!", "bot"); </script> </body> </html>
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值