control跳转到update页面时候URL数据正常,但是数据不能回显,,页面显示400错误。
<%@ 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> <title>欢迎登录学生系统</title> </head> <body> <h3>登录页面</h3> <hr> <form action="control.jsp"> <table> <tr> <td> 用户名: </td> <td> <input type = "text" name = "account"> </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" pageEncoding="utf-8" import = "com.imooc.db.*,com.imooc.info.*,java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>欢迎登录学生通知系统</title> </head> <body> <% Map<String,User>map1 = DbUtil.map1; Map<String,Announcement>map2 = DbUtil.map2; String account = request.getParameter("account"); String password = request.getParameter("password"); User user = new User(account,password); boolean flag = DbUtil.selectByidAndPassword(user); if(flag){ %> <h3>公告列表为:</h3> <hr> <br> <form action="select.jsp"> <table border = "1" width = "500px"> <tr> <td> 公告编号: </td> <td> <input type = "text" name = "id"> </td> <td> <input type = "submit" value = "Select"> </td> </tr> </table> </form> <br> <table width = "500px" border = "1px"> <tr> <td> 编号 </td> <td> 名称 </td> <td> 内容 </td> <td> 删除 </td> <td> 修改 </td> </tr> <% for(String key:map2.keySet()){ Announcement a = map2.get(key); %> <tr> <td> <%= a.getId() %> </td> <td> <%= a.getName() %> </td> <td> <%= a.getContent() %> </td> <td> <a href = "delete.jsp">删除</a> </td> <td> <a href = "update.jsp?id=<%= a.getId() %>&name=<%= a.getName() %>&content=<%= a.getContent() %>">修改</a> </td> </tr> <% } %> </table> <% }else{ %> <h3>用户不存在</h3> <% } %> </body> </html>
control页面
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import = "com.imooc.db.*,com.imooc.info.*,java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>修改公告内容</title> </head> <body> <h3>修改公告信息</h3> <br> <br> <form action = "update_control.jsp"> <table width = "500px" align = "center" border = "1"> <tr> <td> 编号: </td> <td> <input type = "text" 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 = "content" value = "<%=request.getParameter("content") %>"> </td> </tr> <tr> <td colspan = "2"> <input type = "submit" value = "修改"> </td> </tr> </table> </form> </body> </html>
update页面
0
收起
正在回答 回答被采纳积分+1
8回答
chrismorgen
2018-10-18 18:27:24
建议同学重新编译一下工程,点击Project->Clean,可以按下图方法进行操作,
并且建议同学使用chrome浏览器或者火狐浏览器,因为eclipse的内置浏览器的功能不是很完善,有时会出错,祝学习愉快~
chrismorgen
2018-10-16 17:44:16
你可以修改update_control.jsp的代码实现数据的回显。可以参照如下代码进行修改,祝学习愉快~
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import = "com.imooc.db.*,com.imooc.info.*,java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <% Map<String,Announcement>map = DbUtil.map2; Announcement ann = map.get(request.getParameter("id")); ann.setId(request.getParameter("id")); ann.setContent(request.getParameter("content")); ann.setName(request.getParameter("name")); %> <h3>修改成功</h3> <a href="update.jsp?id=<%= ann.getId() %>&name=<%= ann.getName() %>&content=<%= ann.getContent() %>">返回</a> </body> </html>
冲哥_
2018-10-16 14:53:43
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import = "com.imooc.db.*,com.imooc.info.*,java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <% Map<String,Announcement>map = DbUtil.map2; Announcement ann = map.get(request.getParameter("id")); ann.setContent(request.getParameter("content")); ann.setName(request.getParameter("name")); %> <h3>修改成功</h3> </body> </html>
update_control.jsp页面
chrismorgen
2018-10-16 14:42:00
你好同学,你说的回显是什么意思呢?测试了你的代码,修改之后会跳转到update_control.jsp页面,这部分代码同学没有粘贴上来哦,建议你描述一下你想要实现的效果,方便我们具有针对性的为你解答哦,祝学习愉快~
冲哥_
2018-10-16 11:36:46
package com.imooc.info; public class Announcement { private String id; private String name; private String content; public Announcement() { } public Announcement(String id, String name, String content) { super(); this.id = id; this.name = name; this.content = content; } 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 getContent() { return content; } public void setContent(String content) { this.content = content; } }
Announcement类
package com.imooc.info; public class User { private String account; private String password; public User(String account, String password) { super(); this.account = account; this.password = password; } public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
User类
冲哥_
2018-10-15 10:48:03
package com.imooc.db; import java.util.HashMap; import java.util.Map; import com.imooc.info.Announcement; import com.imooc.info.User; public class DbUtil { public static Map<String,User>map1 = new HashMap<String,User>(); public static Map<String,Announcement>map2 = new HashMap<String,Announcement>(); static{ map1.put("1", new User("1","123456")); map2.put("101", new Announcement("101","开学","请同学们9月1日前来报到!")); map2.put("102", new Announcement("102","选课","开始选课啦!")); map2.put("103", new Announcement("103","竞选班委","将于近期竞选班干部!")); map2.put("104", new Announcement("104","评选奖学金","评选奖学金啦!")); } //判读账号和密码是否存在 public static boolean selectByidAndPassword(User user){ boolean flag = false; for(String key:map1.keySet()){ if(map1.get(key).getAccount().equals(user.getAccount()) && map1.get(key).getPassword().equals(user.getPassword())){ flag = true; break; } } return flag; } }
DbUtil.jsp面
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星