为什么我的修改页面跳转不过去......其他功能都没问题
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 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星