Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如果布尔值为True,如何返回字符串_Java_Jsp_Oop_Jakarta Ee - Fatal编程技术网

Java 如果布尔值为True,如何返回字符串

Java 如果布尔值为True,如何返回字符串,java,jsp,oop,jakarta-ee,Java,Jsp,Oop,Jakarta Ee,在学生类中,使用一些值编写构造函数。我想在VIP栏中打印是或否。i、 e当布尔值为true时为是,反之亦然 public class Student { private String firstName; private String lastName; private boolean goldCustomer; public Student(String firstName, String lastName, boolean goldCustomer) { super()

在学生类中,使用一些值编写构造函数。我想在VIP栏中打印是或否。i、 e当布尔值为
true
时为是,反之亦然

public class Student {

private String firstName;
private String lastName;
private boolean goldCustomer;

   public Student(String firstName, String lastName, boolean goldCustomer) {
      super();
      this.firstName = firstName;
      this.lastName = lastName;
      this.goldCustomer = goldCustomer;
   }

  public String getFirstName() {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public boolean isGoldCustomer() {
    return goldCustomer;
  }

  public void setGoldCustomer(boolean goldCustomer) {       
    this.goldCustomer = goldCustomer;       
  }

}
我的JSP页面

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.* , com.jsptag.demo.Student" %>
<%
  List<Student> students = new ArrayList< >();
  students.add( new Student("Rahul" , "Rawat" , false));
  students.add( new Student("Rohit" , "Negi" , true));
  students.add( new Student("Mahesh" , "Gupta" , false));   
  pageContext.setAttribute("myStudents", students);
%>

<html>
<body>
<table border="1">
  <tr>
     <th>First Name</th>
     <th>Last Name</th>
     <th>VIP ?</th>
  </tr>
  <c:forEach var="data" items="${myStudents}">
    <tr> 
      <td>${data.firstName}</td> 
      <td>${data.lastName}</td>  
      <td>${data.goldCustomer}</td> 
    </tr>   
  </c:forEach>  
</table>
</body>
</html>

();
添加(新学生(“Rahul”,“Rawat”,false));
添加(新学生(“Rohit”,“Negi”,true));
添加(新学生(“Mahesh”,“Gupta”,false));
setAttribute(“myStudents”,学生);
%>
名字
姓
贵宾?
${data.firstName}
${data.lastName}
${data.goldCustomer}

它应该与三元运算符一起工作:

<td> ${data.goldCustomer ? 'Yes' : 'No'} </td>
${data.goldCustomer?'Yes':'No'}

它应该与三元运算符一起工作:

<td> ${data.goldCustomer ? 'Yes' : 'No'} </td>
${data.goldCustomer?'Yes':'No'}

我这么做了,但我想我的编码太差了。请也向你解释一下汉克。但是你能告诉我怎么做吗,因为我试过那样做。但我没有成功。我做到了,但我认为我的编码有那么糟糕。请也向你解释一下汉克。但是你能告诉我怎么做吗,因为我试过那样做。但是我没有成功。谢谢先生帮助我。不客气。请随意将我的答案标记为“解决方案”。谢谢先生的帮助。不客气。请随意将我的答案标记为“解决方案”。