显示空白页是哪里出错了呢?
package imooc.jsptest;
public class Users {
private String accout;
private String name;
private String content;
/**
* @param accout
* @param name
* @param content
*/
public Users(String accout, String name, String content) {
super();
this.accout = accout;
this.name = name;
this.content = content;
}
public String getAccout() {
return accout;
}
public void setAccout(String accout) {
this.accout = accout;
}
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 imooc.jsptest1;
import imooc.jsptest.*;
import java.util.*;
public class DBUtil {
public static java.util.Map<String, Users> map = new HashMap<String, Users>();
static {
map.put("101", new Users("101", "开学", "请同学们于9月1日前来报到!"));
map.put("102", new Users("102", "选课", "开始选课啦~"));
map.put("103", new Users("103", "竞选班委", "将于近期竞选班干部~"));
map.put("104", new Users("104", "评选奖学金", "评选奖学金啦~"));
}
public static boolean select(Users us) {
boolean flag =false;
for (String s : map.keySet()) {
Users users = map.get(s);
if (us.getName().equals(users.getName())) {
flag = true;
break;
}
}
return false;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登录界面</title>
</head>
<body>
<h3 align="center">登录界面</h3>
<hr>
<form action="list.jsp">
<table align="center">
<tr>
<td>用户名:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" password="password"></td>
</tr>
<tr>
<td><input type="submit" value="登录"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java"
import="java.util.*,imooc.jsptest.*,java.lang.*,imooc.jsptest1.*"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<title>公告列表</title>
</head>
<body>
<%
String s= request.getParameter("name");
Users users = new Users(null,s, null);
boolean flag = DBUtil.select(users);
Map<String, Users> map = DBUtil.map;
if (flag == true) {
%>
<h3>公告列表为:</h3>
<hr>
<form action="details.jsp">
<table border=1 width=50px>
<tr>
<td><input type="text" value="公告编号:"></td>
<td><input type="text" name=""></td>
<td><input type="submit" value="select"></td>
</tr>
</table>
</form>
<form action="modify.jsp">
<table border=1 width=50px>
<tr>
<td><input type="text" value="编号"></td>
<td><input type="text" value="名称"></td>
<td><input type="text" value="内容"></td>
<td><input type="text" value="删除"></td>
<td><input type="text" value="修改"></td>
</tr>
<%
for (String key : map.keySet()) {
Users us = map.get(key);
%>
<tr>
<td><%=us.getAccout()%></td>
<td><%=us.getName()%></td>
<td><%=us.getContent()%></td>
<td><a href="">删除</a></td>
<td><a href="">修改</a></td>
</tr>
<%
}
%>
</table>
</form>
<%
}
%>
</body>
</html>
运行logon.jsp跳转到list.jsp显示空白页
正在回答
同学的 下图中的地方是否更改了呢?楼上的老师有给你圈出来的。
根据楼上老师的修改,是没有问题的,修改后的代码如下:
DBUtil:
package imooc.jsptest1; import imooc.jsptest.*; import java.util.*; public class DBUtil { public static java.util.Map<String, Users> map = new HashMap<String, Users>(); static { map.put("101", new Users("101", "开学", "请同学们于9月1日前来报到!")); map.put("102", new Users("102", "选课", "开始选课啦~")); map.put("103", new Users("103", "竞选班委", "将于近期竞选班干部~")); map.put("104", new Users("104", "评选奖学金", "评选奖学金啦~")); } public static boolean select(Users us) { boolean flag =false; for (String s : map.keySet()) { Users users = map.get(s); if (us.getAccout().equals(users.getAccout())) { flag = true; break; } } return flag; } }
list.jsp:
<%@ page language="java" import="java.util.*,imooc.jsptest.*,java.lang.*,imooc.jsptest1.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <title>公告列表</title> </head> <body> <% String s= request.getParameter("name"); Users users = new Users(s,null, null); boolean flag = DBUtil.select(users); Map<String, Users> map = DBUtil.map; if (flag == true) { %> <h3>公告列表为:</h3> <hr> <form action="details.jsp"> <table border=1 width=50px> <tr> <td><input type="text" value="公告编号:"></td> <td><input type="text" name=""></td> <td><input type="submit" value="select"></td> </tr> </table> </form> <form action="modify.jsp"> <table border=1 width=50px> <tr> <td><input type="text" value="编号"></td> <td><input type="text" value="名称"></td> <td><input type="text" value="内容"></td> <td><input type="text" value="删除"></td> <td><input type="text" value="修改"></td> </tr> <% for (String key : map.keySet()) { Users us = map.get(key); %> <tr> <td><%=us.getAccout()%></td> <td><%=us.getName()%></td> <td><%=us.getContent()%></td> <td><a href="">删除</a></td> <td><a href="">修改</a></td> </tr> <% } %> </table> </form> <% } %> </body> </html>
其他的页面没有改动。建议同学试一下,并且,看看之前的代码是否都按照老师给你提示的修改了。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
如下图所示,不显示的原因是你比较错对象了,并且你在return的值一直是false,所以执行不了你list
.jsp中flag为true的代码,建议你按照下图进行修改,并将return的返回值改为flag,
package imooc.jsptest1; import imooc.jsptest.*; import java.util.*; public class DBUtil { public static java.util.Map<String, Users> map = new HashMap<String, Users>(); static { map.put("101", new Users("101", "开学", "请同学们于9月1日前来报到!")); map.put("102", new Users("102", "选课", "开始选课啦~")); map.put("103", new Users("103", "竞选班委", "将于近期竞选班干部~")); map.put("104", new Users("104", "评选奖学金", "评选奖学金啦~")); } public static boolean select(Users us) { System.out.println(us.getName()); boolean flag =false; for (String s : map.keySet()) { Users users = map.get(s); if (us.getName().equals(users.getAccout())) { flag = true; break; } } System.out.println(flag); return flag; } }
修订之后的效果如下图,如果我的建议解决了你的问题,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星