【问题标题】:Some other way to display data from sql table on jsp在jsp上显示来自sql表的数据的其他一些方法
【发布时间】:2016-10-30 20:47:23
【问题描述】:

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

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 有没有办法我能做到吗?

【问题讨论】:

    标签: java mysql jsp


    【解决方案1】:

    你可以用&lt;c:choose&gt;标签做到这一点

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

    【讨论】:

      猜你喜欢
      • 2016-04-08
      • 2021-12-03
      • 2015-08-06
      • 1970-01-01
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      相关资源
      最近更新 更多