亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于在jsp中String = null 和String = “”的使用問題!

關于在jsp中String = null 和String = “”的使用問題!

月亮島Superman 2017-08-04 13:32:18
<%@ page language="java" contentType="text/html; charset=gbk"?? ?pageEncoding="gbk"%><%@ page import="java.sql.*"%><%!String str = null;?? ?private void tree(Connection conn, int id, int level) {?? ??? ?Statement stmt = null;?? ??? ?ResultSet rs = null;?? ??? ?String preStr = "";?? ??? ?for (int i = 0; i < level; i++) {?? ??? ??? ?preStr += "----";?? ??? ?}?? ??? ?try {?? ??? ??? ?stmt = conn.createStatement();?? ??? ??? ?String sql = "select * from article where pid = " + id;?? ??? ??? ?rs = stmt.executeQuery(sql);?? ??? ??? ?while (rs.next()) {?? ??? ??? ??? ?str += "<tr><td>" + rs.getInt("id") + "</td><td>" + preStr + rs.getString("title") + "</td></tr>";?? ??? ??? ??? ?if (rs.getInt("isleaf") != 0) {?? ??? ??? ??? ??? ?tree(conn, rs.getInt("id"), level + 1);?? ??? ??? ??? ?}?? ??? ??? ?}?? ??? ?} catch (Exception e) {?? ??? ??? ?e.printStackTrace();?? ??? ?} finally {?? ??? ??? ?try {?? ??? ??? ??? ?if (rs != null) {?? ??? ??? ??? ??? ?rs.close();?? ??? ??? ??? ??? ?rs = null;?? ??? ??? ??? ?}?? ??? ??? ??? ?if (stmt != null) {?? ??? ??? ??? ??? ?stmt.close();?? ??? ??? ??? ??? ?stmt = null;?? ??? ??? ??? ?}?? ??? ??? ?} catch (SQLException e) {?? ??? ??? ??? ?e.printStackTrace();?? ??? ??? ?}?? ??? ?}?? ?}%><%?? ?Class.forName("com.mysql.jdbc.Driver");?? ?//System.out.println("1");?? ?String url = "jdbc:mysql://localhost/test?user=root&password=root";?? ?Connection conn = DriverManager.getConnection(url);?? ?Statement stmt = conn.createStatement();?? ?ResultSet rs = stmt.executeQuery("select * from article where pid = 0");?? ?//System.out.println("2");?? ?while (rs.next()) {?? ??? ?str += "<tr><td>" + rs.getInt("id") + "</td><td>" + rs.getString("title") + "</td></tr>";?? ??? ?System.out.println(str);?? ??? ?if (rs.getInt("isleaf") != 0) {?? ??? ??? ?tree(conn, rs.getInt("id"), 1);?? ??? ?}?? ?}?? ?rs.close();?? ?stmt.close();?? ?conn.close();%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gbk"><title>Insert title here</title></head><body>?? ?<table border="1"><%=str%></table></body></html>問題: String str = null;? 如果我這樣使用 瀏覽器中顯示結果為??? 在表格上方會有一個null? 但是我用String str = “”就不會出現這種問題,這是為什么呢?
查看完整描述

2 回答

?
拖鞋_

TA貢獻453條經驗 獲得超223個贊

JSP 不要學了? 現在都是前端靜態化? 為了? 放入CDN?? JSP? 什么的都不支持的

查看完整回答
1 反對 回復 2017-08-04
?
qq_逆流河_0

TA貢獻1條經驗 獲得超0個贊

null標示你這個String對象不指向具體的內存數據,“”標識你這個對象指向的內存內容是空字符串

查看完整回答
反對 回復 2017-08-04
  • 月亮島Superman
    月亮島Superman
    正因為不指向具體內存數據所以說不可能 在頁面上顯示null啊 這是怎么回事呢
  • 2 回答
  • 0 關注
  • 1930 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號