关于jsp代码在网页中运行只显示一小部分的问题

jsp页面相关问题,idea中能运行,打包为war包后在tomcat中却只能运行一小片代码
如题,代码如下

<h2 class="mingzi">查询条件</h2>
<form action="justsearch">
    <label>
        站点名称
        <input type="text" name="sitename">
    </label>
    <label>
        设备名称
        <input type="text" name="devicename">
    </label>
    <input type="submit" value="搜索" class="button" id="search">
    <input type="button" value="新增" class="button" id="new" onclick="opennewWindow('addnewinfo.jsp',500,500)">
</form>


<table id="myTable" border="1" width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">

      <tr>
        <th colspan="1" class="btbg font-center titfont" rowspan="2">站点名称</th>
        <th width="10%" class="btbg font-center titfont" rowspan="2">设备名称</th>
        <th width="10%" class="btbg font-center titfont" rowspan="2">设备编码</th>
        <th width="10%" class="btbg font-center titfont" rowspan="2">设备分类</th>
        <th>设备类型</th>
        <th>安装时间<br></th>
        <th>设备状态</th>
        <th>操作</th>
      </tr>
    <tbody id = "tbody1">
    <%
        try{
            DBUtil dbUtil = new DBUtil();
            Connection conn = dbUtil.getConnection();
            Statement st;
            ResultSet rs;
            String sql = "SELECT * FROM deviceinfo";
            st = conn.createStatement();
            rs = st.executeQuery(sql);
            while (rs.next()){
        Timestamp installTime = rs.getTimestamp("installTime");
        long timestamp = installTime.getTime();
    %>
        <tr>
            <td><%=rs.getString("siteName")%></td>
            <td><%=rs.getString("deviceName")%></td>
            <td><%=rs.getString("deviceCode")%></td>
            <td><%=rs.getString("deviceCategory")%></td>
            <td><%=rs.getString("deviceType")%></td>
            <td><%=time.formatDateTime(installTime)%></td>
            <td><%=rs.getString("deviceState")%></td>

            <td><a href="javascript:;" onclick = opennewWindow('editinfo.jsp?sitename=<%=rs.getString("siteName")%>&devicename=<%=rs.getString("deviceName")%>&devicecode=<%=rs.getString("deviceCode")%>&devicecategory=<%=rs.getString("deviceCategory")%>&devicetype=<%=rs.getString("deviceType")%>&installtime=<%=timestamp%>&devicestate=<%=rs.getString("deviceState")%>',500,500)>修改</a>
                <a href="javascript:;" onclick = "deleteDevice('<%=rs.getString("deviceCode")%>')">删除</a></td>
        </tr>
    <%
    }
        DBUtil.closeConnection(conn, (PreparedStatement) st,rs);
        }catch (Exception e){
        e.printStackTrace();
    }
    %>
    </tbody>
</table>

在idea中这段代码可以完美运行,但是打包后到tomcat中运行时,却出现了网页代码加载不全的问题,如下图

img

img

一旦删去调用数据库的代码,网页便又能完全读取了。上网查询说是java代码块出现了问题,但是我怎么检查都无法检查出错误来,拜请赐教

可以试试将工程打包,放到tomcat中部署跑一下试试。

  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/7763073
  • 除此之外, 这篇博客: Java查询数据库数据并在网页端显示详细步骤(Idea)中的 写 jsp 页面代码对数据进行展示(以用表格展示数据为例) 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 相当于先写 html 中表格的相关代码,然后在其中加入 Java 代码来实现遍历数据和展示数据

        <table border="1" cellspacing="0">
            <tr>
                <td>ID</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>性别</td>
            </tr>
            <%
                // 里面可以写任意的java代码--jsp脚本
              ArrayList<Student> list = (ArrayList<Student>) request.getAttribute("list");
                for (Student student : list) {
            %>
                    <tr>
                        <td><%=student.getId()%></td>
                        <td><%=student.getName()%>></td>
                        <td><%=student.getAge()%></td>
                        <td><%=student.getGender()%></td>
                    </tr>
            <%
                }
            %>
        </table>
    

F12有报错吗,js是单线程的,加载报错的话, 后面就不动了。