4-8无法正常调整update页面
User.java
package com.imooc.demo; public class User { private String account; //账户名 private String Password; //密码 //构造函数 public User() { } public User(String account, String password) { super(); this.account = account; Password = password; } //getter和setter方法 public String getAccount() { return account; } public void setAccount(String account) { this.account = account; } public String getPassword() { return Password; } public void setPassword(String password) { Password = password; } }
Notice.java
package com.imooc.demo; public class Notice { private String number; //公告编号 private String title; private String content; //构造函数 public Notice() { } public Notice(String number, String title, String content) { super(); this.number = number; this.title = title; this.content = content; } //setter和getter public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } }
DBUtil.java
package com.imooc.dbu; import java.util.HashMap; import java.util.Map; import com.imooc.demo.Notice; import com.imooc.demo.User; public class DBUtil { public static Map<String,Notice> mapNotice = new HashMap<String,Notice>(); public static Map<String,User> mapUser=new HashMap<String,User>(); static { //用户类数据放入数据库 mapUser.put("001",new User("001","123456")); mapUser.put("002",new User("002","123456")); //公告类数据放入数据库 mapNotice.put("101",new Notice("101","开学","请同学们于9月1日前来报道!")); mapNotice.put("102",new Notice("102","选课","开始选课啦~")); mapNotice.put("103",new Notice("103","竞选班委","将于近期竞选班干部~")); mapNotice.put("104",new Notice("104","评选奖学金","评选奖学金啦~")); } //判断用户名和密码是否正确 public static boolean selectNoticeByNumberAndPassword(User user){ boolean flag = false; for(String key:mapUser.keySet()) { User u = mapUser.get(key); if(user.getAccount().equals(u.getAccount()) && user.getPassword().equals(u.getPassword())) { flag = true; break; } } return flag; } }
logon.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h3 align="center">登录页面</h3> <hr/> <form action="control.jsp"> <table align="center"> <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>
control.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.util.*,com.imooc.dbu.*,com.imooc.demo.*"%> <!DOCTYPE html> <html> <head> <title>Insert title here</title> </head> <body> <% //接收logon传入的账号密码信息 String account = request.getParameter("account"); String password = request.getParameter("password"); //接收后进行封装 User user = new User(account,password); //调用方法进行判断,将结果放在flag中 boolean flag = DBUtil.selectNoticeByNumberAndPassword(user); //导入DBUtil中map存放的公告信息 Map<String,Notice> mapNotice = DBUtil.mapNotice; //用flag判断返回语句 if(flag == true){ %> <form action=""> <table align="center" border="1" width="500"> <tr> <td> 编号 </td> <td> 标题 </td> <td> 内容 </td> <td> 删除 </td> <td> 修改 </td> </tr> <% for(String key:mapNotice.keySet()){ Notice n = mapNotice.get(key); %> <tr> <td> <%=n.getNumber() %> </td> <td> <%=n.getTitle() %> </td> <td> <%=n.getContent()%> </td> <td> <a href="update.jsp?number=<%=n.getNumber()%>&title=<%=n.getTitle()%>>&content=<%=n.getContent()%>"> 修改 </a> </td> <td> 删除 </td> </tr> <% }%> </table> </form> <% } else{ out.println("账号和密码错误"); } %> </body> </html>
update
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <title>公告更新页面</title> </head> <body> <h3>修改公告信息</h3> <br/> <form action=""> <table> <tr> <td> 编号: </td> <td> <input type="text" name="number" value="<%=request.getParameter("number")%>"> </td> </tr> <tr> <td> 标题: </td> <td> <input type="text" name="title" value="<%=request.getParameter("title")%>"> </td> </tr> <tr> <td> 内容: </td> <td> <input type="text" name="content" value="<%=request.getParameter("content")%>"> </td> </tr> </table> </form> </body> </html>
经过DBUG,发现问题应该是在control.jsp的第60行,如果传输的值只有number=<%=n.getNumber()%>,那么是可以正常跳转和显示upadate页面,但如果加了title=<%=n.getTitle()%>或content=<%=n.getContent()%>就无法显示,然后又进行尝试让title=<%=n.getTitle()%>和content=<%=n.getContent()%>单独显示,均无法成功,请老师麻烦帮忙看看,谢谢
1
收起
正在回答
1回答
同学的代码经测算是可以正常提交过去的呀,只不过会出现乱码,下边是修改后的update.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <title>公告更新页面</title> </head> <body> <h3>修改公告信息</h3> <br/> <form action=""> <table> <tr> <td> 编号: </td> <td> <input type="text" name="number" value="<%=request.getParameter("number")%>"> </td> </tr> <tr> <td> 标题: </td> <td> <input type="text" name="title" <%String title = request.getParameter("title"); title = new String(title.getBytes("iso-8859-1"),"utf-8"); %> value="<%=title %>"> </td> </tr> <tr> <td> 内容: </td> <td> <input type="text" name="content" <%String content = request.getParameter("content"); content = new String(content.getBytes("iso-8859-1"),"utf-8"); %> value="<%=content%>"> </td> </tr> </table> </form> </body> </html>
另外同学是不是用的IE浏览器呢?建议不要使用IE浏览器,IE浏览器的报错有时不太清晰。
如果我的回答解决了你的问题,请采纳,祝学习愉快.
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星