老师,4-8自由编程修改数据,回显数据的时候网页报错
<%@ 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>
<form action="logon_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>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="com.imooc.test.*,com.imooc.test1.*,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 account=request.getParameter("account");
String password=request.getParameter("password");
Notice no=new Notice(account,password,null,null);
boolean flag=DBNotice.Judge(no);
Map<String,Notice> map=DBNotice.map;
if(flag==true){
%>
<h3 align="center">公告列表为</h3>
<br>
<hr>
<br>
<br>
<form action="select.jsp">
<table align="center" border="1" width="500px" cellspacing="0">
<tr>
<td>公告编号</td>
<td><input type="text" placeholder="null" name="account"/></td>
<td><input type="submit" value="select" /></td>
</tr>
</table>
</form>
<table align="center" border="1" width="500px" cellspacing="0">
<tr>
<td>编号</td>
<td>名称</td>
<td>内容</td>
<td>删除</td>
<td>修改</td>
</tr>
<tr>
<%
for(String key:map.keySet()){
Notice no1=map.get(key);
%>
<tr>
<td><%=no1.getAccount() %></td>
<td><%=no1.getName() %></td>
<td><%=no1.getContent() %></td>
<td><a href="">删除</a></td>
<td><a href="update.jsp?account=<%=no1.getAccount()%>&name=<%=no1.getName()%>&content=<%=no1.getContent()%>">修改</a></td>
</tr>
<%
}
%>
</tr>
</table>
<%
}else{
out.println("登录失败");
}
%>
</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>
<form action="">
<table>
<tr>
<td>编号:</td>
<td><input type="text" value="<%=request.getParameter("account") %>" /></td>
</tr>
<tr>
<td>标题:</td>
<td><input type="text" value="<%=request.getParameter("name") %>"/></td>
</tr>
<tr>
<td>内容:</td>
<td><input type="text" value="<%=request.getParameter("content") %>"/></td>
</tr>
<tr>
<td><input type="submit" value="修改"/></td>
</tr>
</table>
</form>
</body>
</html>正在回答
如下图所示,查询数据时,并没有出现你截图中的报错信息。而标题和内容都是null值,

修改建议,你可以在select.jsp中修改一下代码,请同学参考如下代码与自己代码进行核对,
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="com.imooc.test.*,com.imooc.test1.*,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>
<form action="">
<table>
<tr>
<td>编号:</td>
<td><input type="text" value="<%=request.getParameter("account") %>" /></td>
</tr>
<tr>
<td>标题:</td>
<td><input type="text" value="<%=DBNotice.map.get(request.getParameter("account")).getName() %>"/></td>
</tr>
<tr>
<td>内容:</td>
<td><input type="text" value="<%=DBNotice.map.get(request.getParameter("account")).getContent() %>"/></td>
</tr>
<tr>
<td><input type="submit" value="修改"/></td>
</tr>
</table>
</form>
</body>
</html>修订之后的效果如下图,如有问题,可以继续提问,祝学习愉快~

package com.imooc.test;
public class Notice {
private String account;
private String password;
private String name;
private String content;
public Notice(String account, String password, String name, String content) {
this.account = account;
this.password = password;
this.name = name;
this.content = content;
}
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;
}
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;
}
}package com.imooc.test1;
import java.util.HashMap;
import java.util.Map;
import com.imooc.test.Notice;
public class DBNotice {
public static Map<String,Notice> map=new HashMap();
static {
map.put("101", new Notice("101", "123456","开学", "请同学们于9月1日前来报到"));
map.put("102", new Notice("102", "123456","选课", "开始选课啦~~"));
map.put("103", new Notice("103", "123456","竞选班委", "将于近期竞选班干部"));
map.put("104", new Notice("104", "123456","评选奖学金", "评选奖学金啦~~"));
}
//判断用户名和密码是否正确
public static boolean Judge(Notice no) {
boolean flag=false;
for(String key:map.keySet()) {
Notice no1=map.get(key);
if(no.getAccount().equals(no1.getAccount())&&no.getPassword().equals(no1.getPassword())) {
flag=true;
break;
}
}
return flag;
}
}
建议同学把你的报错提示也粘贴出来,方便老师更准确的帮你定位问题并解答,祝学习愉快~
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星