为什么我的修改页面跳转不过去......其他功能都没问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | package com.work.school; public class School { private String id; private String name; private String information; public School(String id, String name, String information) { super (); this .id = id; this .name = name; this .information = information; } public String getId() { return id; } public void setId(String id) { this .id = id; } public String getName() { return name; } public void setName(String name) { this .name = name; } public String getInformation() { return information; } public void setInformation(String information) { this .information = information; } } package com.work.school; public class User { private String nameId; private String password; public User(String nameId, String password) { super (); this .nameId = nameId; this .password = password; } public String getNameId() { return nameId; } public void setNameId(String nameId) { this .nameId = nameId; } public String getPassword() { return password; } public void setPassword(String password) { this .password = password; } } package com.work.xkdb; import java.util.List; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import com.work.school.School; import com.work.school.User; public class Xk { public static List<User> list = new ArrayList<User>(); public static Map<String, School> map = new HashMap<String,School>(); static { map.put( "101" , new School( "101" , "开学" , "请同学们于9月1日前来报道!" )); map.put( "102" , new School( "102" , "选课" , "开始选课啦~" )); map.put( "103" , new School( "103" , "竞选班委" , "将于近期竞选班干部~" )); map.put( "104" , new School( "104" , "评选奖学金" , "评选奖学金啦~" )); list.add( new User( "gfq" , "123456" )); } //判断用户名和密码是否正确 public static boolean selectUserByAccountAndPassword(User user){ boolean flag = false ; for (User key : list){ if (user.getNameId().equals(key.getNameId()) && user.getPassword().equals(key.getPassword())) { flag = true ; break ; } } return flag; } //查询判断 public static boolean isNoticeExist(String id){ boolean flag = false ; for (String key : map.keySet()) { School school = map.get(key); if (id.equals(school.getId())) { flag = true ; break ; } } return flag; } //增加判断 public static boolean isExist(String id){ boolean flag = false ; for (String key : map.keySet()) { School school = map.get(key); if (id.equals(school.getId())) { flag = true ; break ; } else { flag = false ; break ; } } return flag; } } <%@ page language= "java" contentType= "text/html; charset=utf-8" pageEncoding= "utf-8" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <h1 align= "center" >选课管理系统登录页面</h1> <hr> <!-- action代表了服务器端的处理程序 --> <form action= "control.jsp" > <table align= "center" > <tr> <td>账号:</td> <td> <input type= "text" name= "nameid" /> </td> </tr> <tr> <td>密码:</td> <td> <input type= "password" name= "password" /> </td> </tr> <tr> <td> <input type= "submit" value= "登录" /> </td> </tr> </table> </form> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <!-- 获取账号和密码,并且调用DButil当中的方法来判断是否存在指定信息 request:获取请求信息 getParameter(String name):可以通过一个控件的name属性来获取控件的值 out:输出流对象,输出指定信息 --> <% String nameid = request.getParameter( "nameid" ); String password = request.getParameter( "password" ); User user = new User(nameid,password); boolean flag = Xk.selectUserByAccountAndPassword(user); Map<String,School> map = Xk.map; //List<User> list = Xk.list; if (flag == true ){ Object o = application.getAttribute( "count" ); if (o == null ){ application.setAttribute( "count" , 1 ); } else { int count = Integer.parseInt(o.toString()); application.setAttribute( "count" , count+ 1 ); } session.setAttribute( "nameid" , nameid); %> <h3 align= "right" >登录账户:<%= session.getAttribute( "nameid" ) %></h3> <h3 align= "right" >访问量:<%= application.getAttribute( "count" ) %></h3> <h2 align= "center" >欢迎来到选课管理系统首页</h2> <hr> <form action= "select.jsp" > <table border= "1px" width= "500px" style= "margin-bottom:20px;" align= "center" > <tr> <td>公告内容:</td> <td><input type= "text" name= "id" placeholder= "请输入要查询的编号" /></td> <td><input type= "submit" value= "查询" /></td> </tr> </table> </form> <table align= "center" border= "1" width= "500px" > <tr align= "center" > <td>编号</td> <td>标题</td> <td>内容</td> <td>删除</td> <td>修改</td> </tr> <% for (String key : map.keySet()){ School s = map.get(key); %> <tr align= "center" > <td><%= s.getId()%></td> <td><%= s.getName()%></td> <td><%= s.getInformation()%></td> <!-- 相邻两个jsp页面传递数据的时候,通过URL参数的方式来传递参数 规则: 资源?key=value&key=value --> <td><a href= "delete.jsp?id=<%= s.getId() %>" >删除</a></td> <td><a href= "update.jsp?id=<%= s.getId()%>&name=<%= s.getName()%>&information=<%= s.getInformation()%>" >修改</a></td> </tr> <% } %> </table> <% } else { throw new Exception( "账户和密码错误" ); } %> <div style= "margin-bottom:20px;" align= "center" > <input type= "submit" name= "add" value= "添加公告" class = "join-btn" onclick= "window.location.href='add.jsp'" > <input type= "submit" name= "index" value= "返回登录" class = "join-btn" onclick= "window.location.href='index.jsp'" > </div> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" pageEncoding= "utf-8" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <h3 align= "center" >公告更新界面</h3> <hr/> <h3 align= "right" >登录账户:<%= session.getAttribute( "nameid" ) %></h3> <form action= "update_control.jsp" > <table align= "center" border= "1" width= "250px" > <tr> <td>编号</td> <td><input type= "text" readonly= "readonly" name= "id" value= "<%= request.getParameter(" id ") %>" /></td> </tr> <tr> <td>标题</td> <td><input type= "text" name= "name" value= "<%= request.getParameter(" name ") %>" /></td> </tr> <tr> <td>内容</td> <td><input type= "text" name= "imformation" value= "<%= request.getParameter(" imformation ") %>" /></td> </tr> <tr> <td colspan= "2" ><input type= "submit" value= "修改" /></td> </tr> </table> </form> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <% Map<String,School> map = Xk.map; School school = map.get(request.getParameter( "id" )); school.setId(request.getParameter( "id" )); school.setName(request.getParameter( "name" )); school.setInformation(request.getParameter( "information" )); %> <h3 align= "center" >修改信息成功</h3> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <% String id = request.getParameter( "id" ); boolean flag = Xk.isNoticeExist(id); if (flag == true ){ %> <h2 align= "center" >欢迎来到选课管理系统首页</h2> <hr> <table border= "1px" width= "500px" style= "margin-bottom:20px;" align= "center" > <tr> <td>公告编号:</td> <td><input type= "text" name= "id" value= "null" /></td> <td><input type= "submit" value= "查询" /></td> </tr> </table> <% Map<String,School> map = Xk.map; School s = map.get(id); %> <table align= "center" border= "1" width= "500px" > <tr align= "center" > <td>编号</td> <td>标题</td> <td>内容</td> <td>删除</td> <td>修改</td> </tr> <tr align= "center" > <td><%= s.getId()%></td> <td><%= s.getName()%></td> <td><%= s.getInformation()%></td> <!-- 相邻两个jsp页面传递数据的时候,通过URL参数的方式来传递参数 规则: 资源?key=value&key=value --> <td><a href= "delete.jsp?id=<%= s.getId() %>" >删除</a></td> <td><a href= "update.jsp?id=<%= s.getId()%>&name=<%= s.getName()%>&information=<%= s.getInformation()%>" >修改</a></td> </tr> </table> <% } else { throw new Exception( "您查询的公告不存在!" ); } %> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <% Map<String,School> map = Xk.map; map.remove(request.getParameter( "id" )); %> <h3>删除公告编号为:<%= request.getParameter( "id" )%></h3> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <h3 align= "center" >公告添加界面</h3> <hr/> <form action= "add_control.jsp" > <table align= "center" border= "1" width= "250px" > <tr> <td>编号</td> <td><input type= "text" name= "id1" placeholder= "编号" /></td> </tr> <tr> <td>标题</td> <td><input type= "text" name= "name1" placeholder= "标题" /></td> </tr> <tr> <td>内容</td> <td><input type= "text" name= "information1" placeholder= "内容" /></td> </tr> <tr> <td colspan= "2" ><input type= "submit" value= "修改" /></td> </tr> </table> </form> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" errorPage= "error.jsp" pageEncoding= "utf-8" import = "com.work.school.*,com.work.xkdb.*,java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>Insert title here</title> </head> <body> <% String id = request.getParameter( "id1" ); boolean flag = Xk.isExist(id); if (flag == false ){ Map<String,School> map = Xk.map; map.put(id, new School(id,request.getParameter( "name1" ),request.getParameter( "information1" ))); %> <h3>添加公告编号为:<%= request.getParameter( "id1" )%></h3> <% } else { %> <h3>编号已存在!</h3> <% } %> </body> </html> <%@ page language= "java" contentType= "text/html; charset=utf-8" pageEncoding= "utf-8" isErrorPage= "true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>选课管理系统</title> </head> <body> <!-- exception对象只能在错误页面中使用,page加入一个属性isErrorPage= "true" 有一个页面出现了异常,在页面中指定一个错误处理的页面 ,page指令当中,errorpage来指定 --> <%= exception.getMessage()%> </body> </html> |
27
收起
正在回答
2回答
这是因为在tomcat中默认的编码格式为ISO-8859-1,你可以按照如下方法操作:定义一个String类型的变量str用来接收数据;譬如String str=从其他页面传过来的数据,然后将str进行转码,可以使用如下代码进行转码,String str1=new String(str.getBytes("ISO-8859-1"),"utf-8"); 如果我的建议解决了你的问题,请采纳,祝学习愉快~
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧