2013-07-09 49 views
-1

是否有任何槍擊方法可以查找並檢查空字符串而不會發生異常?檢查Java中的空字符串除了StringUtils

請不要建議StringUtils類。我嘗試了一切,但我無法通過該項目進行編譯。 我使用的是Tomcat,我正在編寫tomcat的根文件夾,我有幾個jsp文件,我無法使用StringUtils進行鏈接。我使用Dreamweaver進行編程。

請幫忙,

+0

可以打開Apache StringUtils.isBlank或isNull的源代碼,並在您的項目中使用相同的代碼。 – Reddy

回答

1

任何錯誤的常用方式?

if (str == null) 

如果「空」你的意思是「空白」也是,然後

if (str == null || str.trim().isEmpty()) 
+0

for blank你需要先修剪字符串,即如果(str == null)|| 。str.trim()的isEmpty()); – veritas

+0

@veritas好點... – Bohemian

+0

感謝你們所有人... – Abhijeet

0

如果你要使用像JSP的功能做如下:

<%! 
// define a isNull() function 
static boolean isNull(String x){ 
    return (x == null || x.isEmpty()); 
} 
%> 

then you can use above function anywhere inside JSP like 

<% if (isNull(xxx)){ %> 
// html code 
<% } %> 
+0

謝謝sooo ...我很喜歡這個......做這個項目的寺廟....所以你們都會得到超然的信用。 .. – Abhijeet