我是把一个HashMap对象保存在一个TXT文件里了,然后想在JSP页面里用增强for循环遍历该对象的value值。可问题是,同样的代码,在Java的console框里能完全显示出,但在JSP页面中却是空白。
这是Messages.java文件的其中一段代码:
public static HashMap<String, Students> messages = new HashMap<String, Students>();
public HashMap<String, Students> getMessages() {// 获得所有信息
File file = new File("../花名册.txt");
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(file));
messages = (HashMap<String, Students>) ois.readObject();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (ois != null) {
ois.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return messages;
}
这是测试代码:
System.out.println("姓名\t学号\t班级\t性别\t年龄\t绩点");
ArrayList<Students> list =new ArrayList<Students>(m.getMessages().values()); for (Students s :list) {
System.out.println(s.getName() + "\t" + s.getID() + "\t" + s.getNO() + "\t" + s.getSex() + "\t"+ s.getAge() + "\t" + s.getGrade());
}
这是JSP里的代码:
<table border="1" cellpadding="0" cellspacing="0">
<tr class="first"><td>学号</td><td>姓名</td><td>班级</td><td>性别</td><td>年龄</td><td>绩点</td></tr>
<%
ArrayList<Students> list =new ArrayList<Students>(m.getMessages().values());
for (Students s : list) {
%>
<tr><td><input type="text" value="<%=s.getID()%>"/></td><td><input type="text" value="<%=s.getName()%>"/></td><td><input type="text" value="<%=s.getNO()%>"/></td><td><input type="text" value="<%=s.getSex()%>"/></td><td><input type="text" value="<%=s.getAge()%>"/></td><td><input type="text" value="<%=s.getGrade()%>"/></td></tr>
<%
}
%>
</table>
我不知道是不是代码错了
这是Messages.java文件的其中一段代码:
public static HashMap<String, Students> messages = new HashMap<String, Students>();
public HashMap<String, Students> getMessages() {// 获得所有信息
File file = new File("../花名册.txt");
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(file));
messages = (HashMap<String, Students>) ois.readObject();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (ois != null) {
ois.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return messages;
}
这是测试代码:
System.out.println("姓名\t学号\t班级\t性别\t年龄\t绩点");
ArrayList<Students> list =new ArrayList<Students>(m.getMessages().values()); for (Students s :list) {
System.out.println(s.getName() + "\t" + s.getID() + "\t" + s.getNO() + "\t" + s.getSex() + "\t"+ s.getAge() + "\t" + s.getGrade());
}
这是JSP里的代码:
<table border="1" cellpadding="0" cellspacing="0">
<tr class="first"><td>学号</td><td>姓名</td><td>班级</td><td>性别</td><td>年龄</td><td>绩点</td></tr>
<%
ArrayList<Students> list =new ArrayList<Students>(m.getMessages().values());
for (Students s : list) {
%>
<tr><td><input type="text" value="<%=s.getID()%>"/></td><td><input type="text" value="<%=s.getName()%>"/></td><td><input type="text" value="<%=s.getNO()%>"/></td><td><input type="text" value="<%=s.getSex()%>"/></td><td><input type="text" value="<%=s.getAge()%>"/></td><td><input type="text" value="<%=s.getGrade()%>"/></td></tr>
<%
}
%>
</table>
我不知道是不是代码错了
