ssm重新开发计科院新闻网站
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <html> 8 <head> 9 <base href="<%=basePath%>"> 10 11 <title>西南石油大学-计算机科学学院</title> 12 <link rel="stylesheet" type="text/css" href="Style01.css"> 13 <link rel="stylesheet" type="text/css" href="css/Iframe.css" /> 14 15 <script type="text/javascript"> 16 function a(){ 17 /*if(""==${sessionScope.Imagenews0Name}){ 18 document.getElementById("reselect").click(); 19 }*/ 20 //alert("你好"); 21 if(${empty sessionScope.Imagenews0Name}){ 22 document.getElementById("reselect").click(); 23 } 24 } 25 </script> 26 </head> 27 28 <body onload="a()"> 29 30 <!-- FFFFFFFFF --> 31 <div style="float:left;margin-left:10px"> 32 <form action="Select" method="get" class="add_cp"> 33 <button type="submit" id="reselect">页面刷新</button> 34 </form> 35 </div> 36 <div style="float:left;margin-left:20px"> 37 <p class="add_cp"><button onclick="window.location.href='login.html'">新闻管理</button></p> 38 </div> 39 40 <!-- 居中显示 --> 41 <div style="display: block; margin: 0 auto; width: 60%; background: #fff;"> 42 <!-- 顶部及搜索 --> 43 <div class="divTop"> 44 <div class="divSearch"> 45 <input type="text" placeholder="请输入关键词搜索"> 46 <input type="submit" value="搜索"> 47 </div> 48 </div> 49 50 <!-- 导航 --> 51 <div class="Guide"> 52 <ul class="ul1"> 53 <li class="li1"><a href="#">网站首页</li> 54 <div class="dropDown"> 55 <a href="#" class="dropBtn">学院概况</a> 56 <div class="dropDown-content"> 57 <a href="#">学院简介</a> 58 <a href="#">学院领导</a> 59 <a href="#">组织机构</a> 60 </div> 61 </div> 62 <div class="dropDown"> 63 <a href="#" class="dropBtn">本科生教育</a> 64 <div class="dropDown-content"> 65 <a href="#">计算机科学与技术专业</a> 66 <a href="#">软件工程专业</a> 67 <a href="#">网络工程专业</a> 68 <a href="#">物联网工程专业</a> 69 <a href="#">信息管理与信息系统专业</a> 70 <a href="#">网络空间安全专业</a> 71 <a href="#">数据科学与大数据技术专业</a> 72 <a href="#">对外人才合作培养项目</a> 73 <a href="#">考试信息</a> 74 <a href="#">选课重修信息</a> 75 <a href="#">通知公告</a> 76 <a href="#">资料下载</a> 77 <a href="#">公选课教师视频</a> 78 </div> 79 </div> 80 <div class="dropDown"> 81 <a href="#" class="dropBtn">研究生教育</a> 82 <div class="dropDown-content"> 83 <a href="#">招生简章</a> 84 <a href="#">计算机科学与技术一级学科</a> 85 <a href="#">软件工程一级学科</a> 86 <a href="#">网络空间安全一级学科</a> 87 <a href="#">研究生导师</a> 88 <a href="#">研究生奖助体系</a> 89 <a href="#">通知公告</a> 90 <a href="#">资料下载</a> 91 </div> 92 </div> 93 <div class="dropDown"> 94 <a href="#" class="dropBtn">师资队伍</a> 95 <div class="dropDown-content"> 96 <a href="#">教授</a> 97 <a href="#">副教授</a> 98 <a href="#">讲师</a> 99 <a href="#">实验人员</a> 100 </div> 101 </div> 102 <div class="dropDown"> 103 <a href="#" class="dropBtn">科学研究</a> 104 <div class="dropDown-content"> 105 <a href="#">科研团队</a> 106 <a href="#">科研平台</a> 107 <a href="#">科研成果</a> 108 </div> 109 </div> 110 <div class="dropDown"> 111 <a href="#" class="dropBtn">学生工作</a> 112 <div class="dropDown-content"> 113 <a href="#">工作动态</a> 114 <a href="#">通知公告</a> 115 <a href="#">课外创新实践</a> 116 <a href="#">毕业生就业</a> 117 <a href="#">心灵之窗</a> 118 <a href="#">青春风采</a> 119 <a href="#">资料下载</a> 120 </div> 121 </div> 122 <div class="dropDown"> 123 <a href="#" class="dropBtn">招生工作</a> 124 <div class="dropDown-content"> 125 <a href="#">学院介绍</a> 126 <a href="#">毕业生就业去向</a> 127 <a href="#">优秀毕业生简介</a> 128 <a href="#">学生获奖</a> 129 <a href="#">精英校友介绍</a> 130 <a href="#">招生工作宣传报道</a> 131 </div> 132 </div> 133 <div class="dropDown"> 134 <a href="#" class="dropBtn">实验中心</a> 135 <div class="dropDown-content"> 136 <a href="#">中心简介</a> 137 <a href="#">实验分室</a> 138 <a href="#">规章制度</a> 139 <a href="#">资料下载</a> 140 <a href="#">开放预约</a> 141 </div> 142 </div> 143 <div class="dropDown"> 144 <a href="#" class="dropBtn">党建之窗</a> 145 <div class="dropDown-content"> 146 <a href="#">党建动态</a> 147 <a href="#">学习园地</a> 148 <a href="#">党务政务公开</a> 149 <a href="#">资料下载</a> 150 </div> 151 </div> 152 </ul> 153 </div> 154 <br> 155 <!-- 滚动图片(暂时静态) --> 156 <div class="divPicture"> 157 <a href="#"><img alt="welcome" src="images/welcome.jpg"></a> 158 </div> 159 160 <!-- 文字新闻版块 --> 161 <div style="width:974px;height:970px;background-color:white;"> 162 <!-- 图片新闻 --> 163 <div class="q1"> 164 <div class="p1"> 165 <div class="t1"> 166 图片新闻 167 </div> 168 <div class="t2"> 169 <a href="#"><img alt="more" src="images/more.png"></a> 170 </div> 171 </div> 172 <div id="sp"> 173 <a><img alt="chat" src="images/chat.jpg" style="width:350px;width:300px"></a> 174 </div> 175 <p> 176 <ul> 177 <li class="li2"><a href="#">${sessionScope.Imagenews0Name}</a></li> 178 <li class="li2"><a href="#">${sessionScope.Imagenews1Name}</a></li> 179 <li class="li2"><a href="#">${sessionScope.Imagenews2Name}</a></li> 180 <li class="li2"><a href="#">${sessionScope.Imagenews3Name}</a></li> 181 <li class="li2"><a href="#">${sessionScope.Imagenews4Name}</a></li> 182 <li class="li2"><a href="#">${sessionScope.Imagenews5Name}</a></li> 183 </ul> 184 </p> 185 </div> 186 <!-- 空行 --> 187 <div class="q"></div> 188 <!-- 学术交流 --> 189 <div class="q2"> 190 <div class="p2"> 191 <div class="t1"> 192 学术交流 193 </div> 194 <div class="t2"> 195 <a href="#"><img alt="more" src="images/more.png"></a> 196 </div> 197 </div> 198 <p> 199 <ul> 200 <li class="li2"><a href="#">基于滑动窗口和模糊c-均</a></li> 201 <li class="li2"><a href="#">基于三支决策的广义代价敏</a></li> 202 <li class="li2"><a href="#">人工智能+:视界充满AI</a></li> 203 <li class="li2"><a href="#">零行列式策略及其网络演化动力学</a></li> 204 <li class="li2"><a href="#">视频遇上云服务</a></li> 205 <li class="li2"><a href="#">计科院关于举行2018年校庆论文报告会的通知</a></li> 206 </ul> 207 </p> 208 </div> 209 210 <!-- 新闻速递 --> 211 <div class="q1"> 212 <div class="p1"> 213 <div class="t1"> 214 新闻速递 215 </div> 216 <div class="t2"> 217 <a href="#"><img alt="more" src="images/more.png"></a> 218 </div> 219 </div> 220 <p> 221 <ul> 222 <li class="li2"><a href="#">计算机科学学院分年级召开</a></li> 223 <li class="li2"><a href="#">学院召开教职工大会学习传达中层干部大会精神 部署学院学期工作</a></li> 224 <li class="li2"><a href="#">计科院工会组织学院女教职工庆祝第109个“三八妇女节”</a></li> 225 <li class="li2"><a href="#">学术讲座——人工智能改变我们的未来生活</a></li> 226 <li class="li2"><a href="#">计算机科学学院各年级辅导员集中走访学生寝室</a></li> 227 <li class="li2"><a href="#">学院召开2018年度领导班子民主生活会</a></li> 228 </ul> 229 </p> 230 </div> 231 <!-- 空行 --> 232 <div class="q"></div> 233 <!-- 党建动态 --> 234 <div class="q2"> 235 <div class="p2"> 236 <div class="t1"> 237 党建动态 238 </div> 239 <div class="t2"> 240 <a href="#"><img alt="more" src="images/more.png"></a> 241 </div> 242 </div> 243 <p> 244 <ul> 245 <li class="li3"><a href="#">学院召开党委中心组学习会暨党</a></li> 246 <li class="li3"><a href="#">学院召开教职工大会学习传达中层...</a></li> 247 <li class="li3"><a href="#">学院召开2018年领导班子民主生...</a></li> 248 <li class="li3"><a href="#">刘翔同志任计算机科学学院党委副...</a></li> 249 <li class="li3"><a href="#">学院党委组织师生收看庆祝改革开...</a></li> 250 <li class="li3"><a href="#">【审核评估】学院召开本科教学工...</a></li> 251 <li class="li3"><a href="#">【聚焦评估】学院召开本科教学工...</a></li> 252 <li class="li3"><a href="#">学院党委开展迎校庆主题党日活动</a></li> 253 </ul> 254 </p> 255 </div> 256 257 <!-- 通知公告 --> 258 <div class="q1" style="height:350px;"> 259 <div class="p1"> 260 <div class="t1"> 261 通知公告 262 </div> 263 <div class="t2"> 264 <a href="#"><img alt="more" src="images/more.png"></a> 265 </div> 266 </div> 267 <p> 268 <ul> 269 <li class="li2"><a href="#">自组团出访前公示信息表(彭博)</a></li> 270 <li class="li2"><a href="#">计算机科学学院2019年春季学期开学教学准备及检查工作实施方案</a></li> 271 <li class="li2"><a href="#">西南石油大学计算机科学学院关于举行学院2019年春季田径运动会的通知</a></li> 272 <li class="li2"><a href="#">2018年秋季学期期末考试情况总结</a></li> 273 <li class="li2"><a href="#">计算机科学学院2018年度教职工考核优秀名单公示</a></li> 274 <li class="li2"><a href="#">国际学术会议(ICCIS2019)征稿通知</a></li> 275 <li class="li2"><a href="#">计算机科学学院领导班子2018年度民主生活会征求意见</a></li> 276 <li class="li2"><a href="#">关于表彰计算机科学学院2018-2019学年秋季学期“最美寝室”的通知</a></li> 277 </ul> 278 </p> 279 </div> 280 <!-- 空行 --> 281 <div class="q"></div> 282 <!-- 专题列表 --> 283 <div class="q2" style="height:350px;"> 284 <div class="p2"> 285 <div class="t1"> 286 专题列表 287 </div> 288 <div class="t2"> 289 <a href="#"><img alt="more" src="images/more.png"></a> 290 </div> 291 </div> 292 <p> 293 <ul> 294 <li class="li3"><a href="#">中美联合高性能和大数据实验室</a></li> 295 <li class="li3"><a href="#">石油工程计算机模拟技术重点实验室</a></li> 296 <li class="li3"><a href="#">思科网络技术学院教师培训中心</a></li> 297 </ul> 298 </p> 299 </div> 300 </div> 301 </div> 302 <!-- 底部 --> 303 <div style="width:100%;height:70px;background-color:#224B77;color: white;text-align: center;line-height:70px;"> 304 Copyright© 2018 All Rights Reserved. 西南石油大学计算机科学学院 305 </div> 306 </body> 307 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>登录</title> 6 <link rel="stylesheet" type="text/css" href="css/index.css" /> 7 </head> 8 9 <body style="background:#fff"> 10 <div class="nav_top"> 11 <div class="nav_tcon"> 12 <div class="logoimg"><img src="images/logo.png" /></div> 13 <div class="logotitle"> 14 <span>新闻后台</span> 15 <p>News</p> 16 </div> 17 <div class="logoname">账号登录</div> 18 </div> 19 </div> 20 <div class="logo_content"> 21 <div class="logo_ccon"> 22 <img class="logobei" src="images/logobei.png" /> 23 <form action="Login01" method="get"> 24 <div class="logo_enter"> 25 <span style="border-bottom:solid 1px #cfcfcf">请使用工作账号进行登陆</span> 26 <span>登录名:</span> 27 <input class="use_name" type="text" name="uname" placeholder="tom" /> 28 <span>登录密码:<a href="index.html">忘记登录密码?</a></span> 29 <input class="use_password" type="password" name="upassword" placeholder="123" /> 30 <button type="submit">登 录</button> 31 <img class="logo_ewm" src="images/ewm.png" /> 32 <div class="logo_zc"><a href="index.html">没有账号?</a></div> 33 </div> 34 </form> 35 </div> 36 </div> 37 <div class="down_info"> 38 <div class="information"> 39 <a href="#">关于我们</a> <a href="#">联系我们</a> <a href="#">法律声明</a> 40 </div> 41 <p>新闻后台 厦门石脉科技</p> 42 <p style="font-size:12px">2015 Stonechat.com版权所有ICP证:鹭B2-22000000 </p> 43 <img style="margin-top:5px" src="images/downbq.png" /> 44 </div> 45 </body> 46 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>添加新闻</title> 6 <link rel="stylesheet" type="text/css" href="css/Iframe.css" /> 7 <link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" /> 8 </head> 9 10 <body> 11 <span class="cp_title">添加新闻</span> 12 <div> 13 <form action="Insert" method="get"> 14 <br><br> 15 <h3 style="margin-left:30px">新闻编号:<input type="text" name="uid"></h3> 16 <br> 17 <h3 style="margin-left:30px">新闻内容:<input type="text" name="uname"></h3> 18 <br> 19 <p class="add_cp" style="width:170px;margin-left:50px"><button type="submit" id="btn">添加新闻</button></p> 20 </form> 21 <p class="add_cp" style="float:left;width:100px"><a href="MyJsp.jsp">返回新闻管理</a></p> 22 </div> 23 </body> 24 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> 10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 11 <title>新闻管理</title> 12 <link rel="stylesheet" type="text/css" href="css/Iframe.css" /> 13 <link rel="stylesheet" href="utilLib/bootstrap.min.css" type="text/css" media="screen" /> 14 </head> 15 16 <body> 17 <span class="cp_title">新闻管理</span> 18 <div class="add_cp"> 19 <a href="Insert.html">+添加新闻</a> 20 <a href="index.jsp" style="margin-left:40px">返回主页</a> 21 <a href="./Select2" style="margin-left:40px">刷新界面</a> 22 </div> 23 24 <div class="table_con"> 25 <table> 26 <tr class="tb_title"> 27 <td width="10%">ID</td> 28 <td width="30%">新闻名</td> 29 <td width="26%">操作</td> 30 </tr> 31 <tr> 32 <td width="10%">${sessionScope.Imagenews0ID}</td> 33 <td width="30%">${sessionScope.Imagenews0Name}</td> 34 <td width="26%"> 35 <input class="bj_btn" type="button" value="编辑" /> 36 <form action="Delete"> 37 <input type="hidden" name="newsid" value="${sessionScope.Imagenews0ID}"}> 38 <input class="del_btn" type="submit" value="删除" /> 39 </form> 40 </td> 41 </tr> 42 <tr> 43 <td width="10%">${sessionScope.Imagenews1ID}</td> 44 <td width="30%">${sessionScope.Imagenews1Name}</td> 45 <td width="26%"> 46 <input class="bj_btn" type="button" value="编辑" /> 47 <form action="Delete"> 48 <input type="hidden" name="newsid" value="${sessionScope.Imagenews1ID}"}> 49 <input class="del_btn" type="submit" value="删除" /> 50 </form> 51 </td> 52 </tr> 53 <tr> 54 <td width="10%">${sessionScope.Imagenews2ID}</td> 55 <td width="30%">${sessionScope.Imagenews2Name}</td> 56 <td width="26%"> 57 <input class="bj_btn" type="button" value="编辑" /> 58 <form action="Delete"> 59 <input type="hidden" name="newsid" value="${sessionScope.Imagenews2ID}"}> 60 <input class="del_btn" type="submit" value="删除" /> 61 </form> 62 </td> 63 </tr> 64 <tr> 65 <td width="10%">${sessionScope.Imagenews3ID}</td> 66 <td width="30%">${sessionScope.Imagenews3Name}</td> 67 <td width="26%"> 68 <input class="bj_btn" type="button" value="编辑" /> 69 <form action="Delete"> 70 <input type="hidden" name="newsid" value="${sessionScope.Imagenews3ID}"> 71 <input class="del_btn" type="submit" value="删除" /> 72 </form> 73 </td> 74 </tr> 75 <tr> 76 <td width="10%">${sessionScope.Imagenews4ID}</td> 77 <td width="30%">${sessionScope.Imagenews4Name}</td> 78 <td width="26%"> 79 <input class="bj_btn" type="button" value="编辑" /> 80 <form action="Delete"> 81 <input type="hidden" name="newsid" value="${sessionScope.Imagenews4ID}"> 82 <input class="del_btn" type="submit" value="删除" /> 83 </form> 84 </td> 85 </tr> 86 <tr> 87 <td width="10%">${sessionScope.Imagenews5ID}</td> 88 <td width="30%">${sessionScope.Imagenews5Name}</td> 89 <td width="26%"> 90 <input class="bj_btn" type="button" value="编辑" /> 91 <form action="Delete"> 92 <input type="hidden" name="newsid" value="${sessionScope.Imagenews5ID}"> 93 <input class="del_btn" type="submit" value="删除" /> 94 </form> 95 </td> 96 </tr> 97 </table> 98 </div> 99 </body> 100 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 @CHARSET "UTF-8"; 2 3 .divTop{width: 974px; 4 height:117px; 5 background-image:url(images/top-bg.jpg);} 6 7 .divSearch{ width:280px; 8 height:100px; 9 float:right; 10 margin-top:45px; 11 margin-right:0px;} 12 13 .Guide{width:974px; 14 height:80px; 15 background-color:white; 16 } 17 18 .ul1{ 19 width:974px; 20 list-style-type: none; 21 margin: 0px; 22 padding: 0px; 23 overflow: hidden; 24 background-color: #0B6CB8; 25 } 26 .li1{ 27 float:left; 28 } 29 .li1 a,.dropBtn{ 30 display: inline-block; 31 color: white; 32 text-align: center; 33 padding: 15px 13px; 34 text-decoration: none; 35 } 36 .dropDown{ 37 display:inline-block; 38 } 39 .dropDown-content{ 40 display:none; 41 position: absolute; 42 background-color: #0A5894; 43 min-width: 160px; 44 } 45 .dropDown-content a { 46 display: block; 47 color: white; 48 padding: 10px 10px; 49 text-decoration: none; 50 } 51 .dropDown-content a:hover { 52 background-color: #0D6DB9; 53 } 54 .dropDown:hover .dropDown-content{ 55 display:block; 56 } 57 58 .divPicture{ 59 width:974px; 60 height:200px; 61 } 62 63 .q{ 64 float:left; 65 width:24px; 66 height:300px; 67 } 68 69 .q1{ 70 float:left; 71 width:630px; 72 height:300px; 73 background-color:white; 74 } 75 .q2{ 76 float:left; 77 width:320px; 78 height:300px; 79 background-color:white; 80 } 81 .p1{ 82 float:left; 83 width:630px; 84 height:30px; 85 background-color:#dddddd; 86 } 87 .p2{ 88 float:left; 89 width:320px; 90 height:30px; 91 background-color:#dddddd; 92 } 93 .t1{ 94 color:white; 95 text-align: center; 96 float:left; 97 width:100px; 98 height:30px; 99 background-color:#2780CB; 100 } 101 .t2{ 102 padding-top:13px; 103 align:center; 104 float:right; 105 width:50px; 106 height:30px; 107 } 108 #sp{ 109 width:350px; 110 height:250px; 111 background-color:white; 112 float:left; 113 } 114 .li2{ 115 padding: 10px 10px; 116 } 117 .li2 a{ 118 text-decoration: none; 119 color:black; 120 } 121 .li3{ 122 padding: 5px 0px; 123 } 124 .li3 a{ 125 text-decoration: none; 126 color:gray; 127 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.a; 2 3 import java.sql.DriverManager; 4 import java.sql.ResultSet; 5 import java.util.ArrayList; 6 7 import javax.security.auth.message.callback.PrivateKeyCallback.Request; 8 9 import com.mysql.jdbc.Connection; 10 import com.mysql.jdbc.PreparedStatement; 11 import com.mysql.jdbc.Statement; 12 import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List; 13 14 public class DBHelper { 15 String dirver = "com.mysql.jdbc.Driver";//驱动类名 16 String url = "jdbc:mysql://localhost:3306/newsdb?useUnicode=true&characterEncoding=UTF8"; 17 String user="root"; 18 String password="zhoujunjie"; 19 Connection con=null; 20 21 java.util.List<NewsInfo> NewsSelect=new ArrayList<NewsInfo>(); 22 23 public void connect(){ 24 try{ 25 Class.forName(dirver);//加载驱动程序 26 con=(Connection)DriverManager.getConnection(url,user,password); 27 if(!con.isClosed()){ 28 System.out.println("连接数据库成功"); 29 } 30 }catch(Exception e){ 31 e.printStackTrace(); 32 } 33 } 34 35 //关闭连接方法 36 public void close(){ 37 try { 38 this.con.close(); 39 } catch (Exception e) { 40 e.printStackTrace(); 41 } 42 } 43 44 //查询方法 45 public void select(String sql){ 46 try { 47 Statement stmt=(Statement)this.con.createStatement(); 48 ResultSet rs=(ResultSet)stmt.executeQuery(sql); 49 rs.getRow(); 50 51 while(rs.next()){ 52 int id=rs.getInt("NewsID"); 53 String name=rs.getString("NewsName"); 54 NewsInfo news=new NewsInfo(); 55 news.id=id; 56 news.name=name; 57 58 NewsSelect.add(news); 59 } 60 stmt.close(); 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 } 65 //获取查询数据方法 66 public java.util.List<NewsInfo> myselect(){ 67 return NewsSelect; 68 } 69 70 //删除方法 71 public void delete(String newsid){ 72 String sql="delete from imagenews where NewsID=?"; 73 try { 74 PreparedStatement prestmt=(PreparedStatement)con.prepareStatement(sql); 75 prestmt.setString(1,newsid); 76 77 prestmt.executeUpdate(); 78 System.out.println("删除成功"); 79 prestmt.close(); 80 } catch (Exception e) { 81 e.printStackTrace(); 82 } 83 } 84 85 //插入方法 86 public void add(String newsid,String newsname){ 87 String sql="insert into imagenews(NewsID,NewsName) values(?,?)"; 88 try { 89 PreparedStatement prestmt=(PreparedStatement)con.prepareStatement(sql); 90 prestmt.setString(1,newsid); 91 prestmt.setString(2,newsname); 92 93 prestmt.executeUpdate(); 94 System.out.println("插入成功"); 95 prestmt.close(); 96 } catch (Exception e) { 97 e.printStackTrace(); 98 } 99 } 100 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.a; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 @WebServlet("/Login01") 13 public class Login extends HttpServlet { 14 15 /** 16 * The doGet method of the servlet. <br> 17 * 18 * This method is called when a form has its tag value method equals to get. 19 * 20 * @param request the request send by the client to the server 21 * @param response the response send by the server to the client 22 * @throws ServletException if an error occurred 23 * @throws IOException if an error occurred 24 */ 25 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 26 //设置请求和响应的字符集编码 27 response.setContentType("text/html; charset=UTF-8"); 28 request.setCharacterEncoding("UTF-8"); 29 PrintWriter out = response.getWriter(); //获得输出流 30 //从请求对象中获得指定参数的值 31 32 String strName = request.getParameter("uname"); 33 String strPassWord = request.getParameter("upassword"); 34 if("tom".equals(strName)&&"123".equals(strPassWord)) 35 { 36 response.sendRedirect("MyJsp.jsp"); 37 } 38 else{ 39 out.println("账号或密码错误,请返回"); 40 } 41 } 42 43 /** 44 * The doPost method of the servlet. <br> 45 * 46 * This method is called when a form has its tag value method equals to post. 47 * 48 * @param request the request send by the client to the server 49 * @param response the response send by the server to the client 50 * @throws ServletException if an error occurred 51 * @throws IOException if an error occurred 52 */ 53 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 54 doGet(request, response); 55 } 56 57 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.a; 2 3 public class NewsInfo { 4 int id; 5 String name; 6 7 public void setId(int id) { 8 this.id = id; 9 } 10 public void setName(String name) { 11 this.name = name; 12 } 13 public int getId() { 14 return id; 15 } 16 public String getName() { 17 return name; 18 } 19 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.b; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 import com.a.DBHelper; 14 import com.a.NewsInfo; 15 16 @WebServlet("/Select") 17 public class Select extends HttpServlet { 18 19 /** 20 * The doGet method of the servlet. <br> 21 * 22 * This method is called when a form has its tag value method equals to get. 23 * 24 * @param request the request send by the client to the server 25 * @param response the response send by the server to the client 26 * @throws ServletException if an error occurred 27 * @throws IOException if an error occurred 28 */ 29 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 //设置请求和响应的字符集编码 31 response.setContentType("text/html; charset=UTF-8"); 32 request.setCharacterEncoding("UTF-8"); 33 PrintWriter out = response.getWriter(); //获得输出流 34 35 /* 36 //数据库连接 37 DBHelper dbhelper=new DBHelper(); 38 dbhelper.connect(); 39 //执行6次查询 40 String[] newstime=new String[]{"imagenews","academicexchange","newsnow","partyactive","notice","spetiallist"}; 41 for(int time=0;time<newstime.length;time++){ 42 String sql="select * from "+newstime[time]; 43 dbhelper.select(sql); 44 List<NewsInfo> newsall=dbhelper.myselect(); 45 46 for(int i=0;i<newsall.size();i++){ 47 NewsInfo Imagenews = newsall.get(i); 48 request.getSession().setAttribute(newstime[time]+i+"ID", Imagenews.getId()); 49 request.getSession().setAttribute(newstime[time]+i+"Name", Imagenews.getName()); 50 } 51 } 52 */ 53 54 for(int q=0;q<6;q++){ 55 if(null!=request.getSession().getAttribute("Imagenews"+q+"ID")){ 56 request.getSession().removeAttribute("Imagenews"+q+"ID"); 57 request.getSession().removeAttribute("Imagenews"+q+"Name"); 58 } 59 } 60 61 62 DBHelper dbhelper=new DBHelper(); 63 dbhelper.connect(); 64 String sql="select * from imagenews"; 65 dbhelper.select(sql); 66 67 List<NewsInfo> newsall=dbhelper.myselect(); 68 for(int i=0;i<newsall.size();i++){ 69 NewsInfo Imagenews = newsall.get(i); 70 request.getSession().setAttribute("Imagenews"+i+"ID", Imagenews.getId()); 71 request.getSession().setAttribute("Imagenews"+i+"Name", Imagenews.getName()); 72 } 73 74 dbhelper.close(); 75 76 response.sendRedirect("index.jsp"); 77 } 78 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 79 doGet(request, response); 80 } 81 82 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.b; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.util.List; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 import com.a.DBHelper; 14 import com.a.NewsInfo; 15 16 @WebServlet("/Select2") 17 public class Select2 extends HttpServlet { 18 19 /** 20 * The doGet method of the servlet. <br> 21 * 22 * This method is called when a form has its tag value method equals to get. 23 * 24 * @param request the request send by the client to the server 25 * @param response the response send by the server to the client 26 * @throws ServletException if an error occurred 27 * @throws IOException if an error occurred 28 */ 29 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 //设置请求和响应的字符集编码 31 response.setContentType("text/html; charset=UTF-8"); 32 request.setCharacterEncoding("UTF-8"); 33 PrintWriter out = response.getWriter(); //获得输出流 34 35 /* 36 //数据库连接 37 DBHelper dbhelper=new DBHelper(); 38 dbhelper.connect(); 39 //执行6次查询 40 String[] newstime=new String[]{"imagenews","academicexchange","newsnow","partyactive","notice","spetiallist"}; 41 for(int time=0;time<newstime.length;time++){ 42 String sql="select * from "+newstime[time]; 43 dbhelper.select(sql); 44 List<NewsInfo> newsall=dbhelper.myselect(); 45 46 for(int i=0;i<newsall.size();i++){ 47 NewsInfo Imagenews = newsall.get(i); 48 request.getSession().setAttribute(newstime[time]+i+"ID", Imagenews.getId()); 49 request.getSession().setAttribute(newstime[time]+i+"Name", Imagenews.getName()); 50 } 51 } 52 */ 53 54 for(int q=0;q<6;q++){ 55 if(null!=request.getSession().getAttribute("Imagenews"+q+"ID")){ 56 request.getSession().removeAttribute("Imagenews"+q+"ID"); 57 request.getSession().removeAttribute("Imagenews"+q+"Name"); 58 } 59 } 60 61 62 DBHelper dbhelper=new DBHelper(); 63 dbhelper.connect(); 64 String sql="select * from imagenews"; 65 dbhelper.select(sql); 66 67 List<NewsInfo> newsall=dbhelper.myselect(); 68 for(int i=0;i<newsall.size();i++){ 69 NewsInfo Imagenews = newsall.get(i); 70 request.getSession().setAttribute("Imagenews"+i+"ID", Imagenews.getId()); 71 request.getSession().setAttribute("Imagenews"+i+"Name", Imagenews.getName()); 72 } 73 74 dbhelper.close(); 75 76 response.sendRedirect("MyJsp.jsp"); 77 } 78 79 /** 80 * The doPost method of the servlet. <br> 81 * 82 * This method is called when a form has its tag value method equals to post. 83 * 84 * @param request the request send by the client to the server 85 * @param response the response send by the server to the client 86 * @throws ServletException if an error occurred 87 * @throws IOException if an error occurred 88 */ 89 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 90 doGet(request, response); 91 } 92 93 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.c; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import com.a.DBHelper; 13 14 @WebServlet("/Delete") 15 public class Delete extends HttpServlet { 16 17 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 18 //设置请求和响应的字符集编码 19 response.setContentType("text/html; charset=UTF-8"); 20 request.setCharacterEncoding("UTF-8"); 21 PrintWriter out = response.getWriter(); //获得输出流 22 23 String strID = request.getParameter("newsid"); 24 DBHelper dbhelper=new DBHelper(); 25 dbhelper.connect(); 26 if(""!=strID){ 27 dbhelper.delete(strID); 28 out.println("删除成功!请返回"); 29 } 30 31 dbhelper.close(); 32 } 33 34 /** 35 * The doPost method of the servlet. <br> 36 * 37 * This method is called when a form has its tag value method equals to post. 38 * 39 * @param request the request send by the client to the server 40 * @param response the response send by the server to the client 41 * @throws ServletException if an error occurred 42 * @throws IOException if an error occurred 43 */ 44 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 45 doGet(request, response); 46 } 47 48 }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 package com.c; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import com.a.DBHelper; 13 14 @WebServlet("/Insert") 15 public class Insert extends HttpServlet { 16 17 /** 18 * The doGet method of the servlet. <br> 19 * 20 * This method is called when a form has its tag value method equals to get. 21 * 22 * @param request the request send by the client to the server 23 * @param response the response send by the server to the client 24 * @throws ServletException if an error occurred 25 * @throws IOException if an error occurred 26 */ 27 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 28 //设置请求和响应的字符集编码 29 response.setContentType("text/html; charset=UTF-8"); 30 request.setCharacterEncoding("UTF-8"); 31 PrintWriter out = response.getWriter(); //获得输出流 32 33 String strID = request.getParameter("uid"); 34 String strName = request.getParameter("uname"); 35 DBHelper dbhelper=new DBHelper(); 36 dbhelper.connect(); 37 if(""!=strID&&""!=strName){ 38 dbhelper.add(strID, strName); 39 out.println("插入成功!请返回"); 40 } 41 42 dbhelper.close(); 43 } 44 45 /** 46 * The doPost method of the servlet. <br> 47 * 48 * This method is called when a form has its tag value method equals to post. 49 * 50 * @param request the request send by the client to the server 51 * @param response the response send by the server to the client 52 * @throws ServletException if an error occurred 53 * @throws IOException if an error occurred 54 */ 55 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 56 doGet(request, response); 57 } 58 59 }