用EL和JSTL显示查询结果显示不出来
代码如下:Student.javapackagebean;publicclassStudent{privateStringsno,sname,sex;publicStud...
代码如下:Student.java
package bean;
public class Student{
private String sno,sname,sex;
public Student(String sno,String sname,String sex){
this.sno = sno;
this.sname = sname;
this.sex = sex;
}
public String getSno(){return sno;}
public void setSno(String sno){this.sno = sno;}
public String getSname(){ return sname;}
public void setSname(String sname){this.sname = sname;}
public String getSex(){return sex;}
public void setSex(String sex){this.sex = sex;}
}
实现数据的创建和保存的servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<Student> studentlist=new ArrayList<Student>();//查询结果
Student aa=new Student("001","张三","男");
studentlist.add(aa);
Student bb=new Student("002","李四","女");
studentlist.add(bb);
Student cc=new Student("003","王五","男");
studentlist.add(cc);
request.setAttribute("result", studentlist);//将查询结果保存到request对象中
//转发到show.jsp显示查询结果
request.getRequestDispatcher("index.jsp").forward(request, response);
}
以及显示界面:
<%@ page pageEncoding="utf-8" import="java.util.*,bean.Student"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
显示结果(用EL和JSTL)<br/>
<table border="1">
<tr><th>学号</th><th>姓名</th><th>性别</th></tr>
<c:forEach var="student" items="${result}">
<tr><td>${student.sno}</td><td>${student.sname}</td><td>${student.sex}</td></tr>
</c:forEach>
</table>
</body>
</html>
结果怎么会是这样 展开
package bean;
public class Student{
private String sno,sname,sex;
public Student(String sno,String sname,String sex){
this.sno = sno;
this.sname = sname;
this.sex = sex;
}
public String getSno(){return sno;}
public void setSno(String sno){this.sno = sno;}
public String getSname(){ return sname;}
public void setSname(String sname){this.sname = sname;}
public String getSex(){return sex;}
public void setSex(String sex){this.sex = sex;}
}
实现数据的创建和保存的servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<Student> studentlist=new ArrayList<Student>();//查询结果
Student aa=new Student("001","张三","男");
studentlist.add(aa);
Student bb=new Student("002","李四","女");
studentlist.add(bb);
Student cc=new Student("003","王五","男");
studentlist.add(cc);
request.setAttribute("result", studentlist);//将查询结果保存到request对象中
//转发到show.jsp显示查询结果
request.getRequestDispatcher("index.jsp").forward(request, response);
}
以及显示界面:
<%@ page pageEncoding="utf-8" import="java.util.*,bean.Student"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
显示结果(用EL和JSTL)<br/>
<table border="1">
<tr><th>学号</th><th>姓名</th><th>性别</th></tr>
<c:forEach var="student" items="${result}">
<tr><td>${student.sno}</td><td>${student.sname}</td><td>${student.sex}</td></tr>
</c:forEach>
</table>
</body>
</html>
结果怎么会是这样 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
展开全部
EL即ExpressionLanguage(表达式语言) EL的语法:${ELexprission} ${bean.name}或${bean['name']} 说白了,EL是用来显示数据的,功能跟<%=表达式%>一样,EL是不需要引入什么东西的 JSTL(...
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请执行该Servlet而不是jsp,接着你就会见到奇迹。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询