2016-06-28 65 views
1

我已经使用jstl在found.jsp上显示来自表名为status(所有列都是字符串类型)的特定数据。在我的表中,我在状态列下输入1和0,其中1代表IN,0代表OUT。从jsp上的sql表显示数据的其他方法

found.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@ page import="java.io.*,java.util.*,java.sql.*"%> 
<%@ page import="javax.servlet.http.*,javax.servlet.*" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>Found page</title> 
    <style> 
     header { 
      background-color:teal; 
      color:white; 
      text-align:center; 
      padding:5px; 
     } 
     section { 
      height:270px; 
      width:1050px; 
      float:right; 
      padding:87px; 
     } 
     footer { 
      background-color:black; 
      float:bottom; 
      color:white; 
      clear:both; 
      text-align:center; 
      padding:5px; 
     } 
    </style> 
</head> 
<body style="background-color:lightsteelblue;"> 
    <header><h3>File Status!!</h3> 
     <br> 
    </header> 
    <a href="create1.jsp"><font color="black">back</font></a> 

    <form action=" LogoutServlet" method="post"> 
     <input type="submit" value="Logout" > 
    </form> 
    <form method="POST"> 
     File Number:<input type="text" name="status" value="" size="20" /> 
     <input type="submit" value="submit" name="submit" /> 
    </form> 
    <br> 
    <section> 
     <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" 
          url="jdbc:mysql://localhost/login" 
          user="root" password="root"/> 

     <sql:query dataSource="${snapshot}" var="result"> 
      SELECT * from status where fname="${param.status}"; 
     </sql:query> 

     <table border="1" width="100%"> 
      <tr> 
       <th>File Number</th> 

下面就是1和0显示的列下

   <th>File Status(IN=1 and OUT=0)</th> 
       <th>File Department</th> 
       <th>Date and Time</th> 
      </tr> 
      <c:forEach var="row" items="${result.rows}"> 
       <tr> 
        <td><c:out value="${row.fname}"/></td> 

价值来源于这里

    <td><c:out value="${row.fstatus}"/></td> 
        <td><c:out value="${row.department}"/></td> 
        <td><c:out value="${row.datetime}"/></td> 
       </tr> 
      </c:forEach> 
     </table> 
    </section> 
    <footer> 
     Copyright 2016 NSIC. All right reserved.        
    </footer> 
</body> 
</html> 

我不想和1 0来显示,而不是我想IN和OUT显示在列下,我不想改变数据库表使用从1和0到IN和OUT有没有办法可以做到这一点?

回答

1

你可以用<c:choose>标签做

<c:choose> 
    <c:when test="${row.fstatus=='1'}"> 

     IN 

    </c:when>  
    <c:otherwise> 

     OUT 

    </c:otherwise> 
</c:choose>