gpt4 book ai didi

java - 在 JSTL 中显示 bean

转载 作者:行者123 更新时间:2023-11-30 04:36:17 24 4
gpt4 key购买 nike

我在使用 JSTL 显示 Bean 的详细信息时遇到问题。我的servlet代码如下

 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

String username =request.getParameter("username");
String password = request.getParameter("password");
try {

con = connection.connectionfile();

pstmt=con.prepareStatement("select * from Login where Username=? and Password=?");
pstmt.setString(1,username);
pstmt.setString(2, password);
rs = pstmt.executeQuery();

if(rs.next())
{
ListGrabber grabber = new ListGrabber();
List<DvdDetail> list = new ArrayList<DvdDetail>();
list=grabber.getBeanList();

request.setAttribute("listbean",list);
RequestDispatcher view = request.getRequestDispatcher("listdetail.jsp");

view.forward(request, response);


}
else
{
response.sendRedirect("loginerror.html");
}

}
catch(Exception ex)
{
ex.printStackTrace();
}

finally {
out.close();
try
{
rs.close();
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}

Bean如下:

   public class DvdDetail {

private int id;
private String film_name;
private String released_date;
private String directed_by;
private String actor_name;
private String actress_name;
private int price;
private String banner;

public DvdDetail(int id,String film_name,String released_date,String directed_by,String actor_name,String actress_name,int price,String banner)
{

this.id=id;
this.film_name=film_name;
this.released_date=released_date;
this.directed_by=directed_by;
this.actor_name=actor_name;
this.actress_name=actress_name;
this.price=price;
this.banner=banner;

}

public String getActor_name() {
return actor_name;
}

public void setActor_name(String actor_name) {
this.actor_name = actor_name;
}

public String getActress_name() {
return actress_name;
}

public void setActress_name(String actress_name) {
this.actress_name = actress_name;
}

public String getBanner() {
return banner;
}

public void setBanner(String banner) {
this.banner = banner;
}

public String getDirected_by() {
return directed_by;
}

public void setDirected_by(String directed_by) {
this.directed_by = directed_by;
}

public String getFilm_name() {
return film_name;
}

public void setFilm_name(String film_name) {
this.film_name = film_name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getReleased_date() {
return released_date;
}

public void setReleased_date(String released_date) {
this.released_date = released_date;
}



}

如何在 JSP 页面中打印多个电影名称,但仅使用 JSTL。在JSP中我通常将其解决为

List<DvdDetail> list = request.getParameter("listbean");
for(int i=0;i<list.size();i++)
{
DvdDetail bean = list.get(i);
///displaying usng out.print(bean.getProperty());
}

我需要实现同样的目标,但是使用 JSTL。

最佳答案

点击info link在您在问题中添加的 JSTL 标记的弹出窗口中,以获取有关 JSTL 的信息和教程链接。

你想要实现的目标可以这样完成:

<ul>
<c:forEach var="dvd" items="${listbean}">
<li><c:out value="${dvd.film_name}"/></li>
</c:forEach>
</ul>

关于java - 在 JSTL 中显示 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13432721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com