⑴ jsp 中如何判斷字元串為空
你說的空是什麼概念?是長度為0的字串還是沒有被初使化的字串?
如果兩者都有,比如字串變數是string, 可以用
if(string==null || "".equals(string){
// 這是空字串
}
⑵ jsp中如何判斷一個字元變數是否為空或者null
在頁面上可以用C標簽.
<c:if test="${empty str}">
str為空
</c:if>
<c:if test="${not empty str}">
str不為空
</c:if>
或者:
<c:choose>
<c:when test="${empty 字元變數}">
字元變數為空
</c:when>
<c:otherwise>
字元變數不為空
</c:otherwise>
</c:choose>
⑶ 在jsp中,我怎麼樣判斷他的結果集是否為空
比如後台傳了一個list
jsp中:
<!--list為空-->
<c:iftest="${emptylist}">
</c:if>
<!--list不為空-->
<c:iftest="${notemptylist}">
</c:if>
⑷ jsp 判斷為空
代碼及說明參考下面代碼及代碼中的注釋
java"><%@pagelanguage="java"pageEncoding="GB2312"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<html>
<head>
<!--在JSP中添加javascript代碼,防止用戶空提交-->
<scriptlanguage="javascript">
functioncheckValidate()
{
//判斷用戶名是否為空
if(document.form1.textfield1.value==""||document.form1.textfield1.value==null)
{
window.alert("用戶名不能為空!!!");
returnfalse;
}
//判斷手機號是否為空
if(document.form1.textfield2.value==""||document.form1.textfield2.value==null)
{
window.alert("手機號不能為空!!!");
returnfalse;
}
//判斷密碼是否為空
if(document.form1.textfield3.value==""||document.form1.textfield3.value==null)
{
window.alert("密碼不能為空!!!");
returnfalse;
}
}
</script>
<basehref="<%=basePath%>">
<title>register.jsp頁面</title>
<!--
<linkrel="stylesheet"type="text/css"href="styles.css">
-->
</head>
<bodybgcolor=cyan>
<formid="form1"name="form1"method="post"action="RegisterValidate.jsp">
<p><imgsrc="file:///D|/MyEclipseWorkPlace5.5/MyProject0/WebRoot/loginpictures/register.jpg"width="203"height="137"/></p>
<p><strong>用戶名:
<inputname="textfield1"type="text"/>
</strong></p>
<p><strong>手機號:</strong>
<inputtype="text"name="textfield2"/>
</p>
<p><strong>密碼:</strong>
<inputtype="password"name="textfield3"/>
</p>
<p><strong>確認密碼:</strong>
<inputtype="password"name="textfield4"/>
</p>
<p>
<inputtype="submit"name="Submit"value="免費注冊"onclick="returncheckValidate();"/>
<inputtype="reset"name="Reset"value="重置"/>
</p>
</form>
</body>
</html>
⑸ 新手求救!jsp 數組、for、if怎樣實現判斷空值
<script language="javascript">
function JTrim(s) {
return s.replace(/(^\s*)|(\s*$)/g, "");
}
function btn() {
var arr=['fzxm','fzsfz','fwdz','czrxm',''];
for(var j=0;j<arr.length;j++){
var t=arr[j];
alert(JTrim(t));
if (JTrim(t)==""){
alert("請輸入查詢內容!");
return;
}
else{
continue;
}
}
}
</script>
你的代碼兩個問題:第一字元串類型數組沒有加 引號。第二個循環使用數組的length,而不要固定最大值
⑹ 關於JSP判斷輸入是否為空或空格的問題
應該說有3個方向可供選擇
第一個是使用原生的JavaScript編寫,判斷,控制css顯示提示內容, 這樣麻煩些
第二個就是使用jQuery的相關驗證插件,很方便.
如果使用了前段框架[比如easyUI, bootstrap等]更簡單了,按照要求寫一點js
⑺ jsp頁面如何查詢,特別是空值怎麼查詢
定義一個查詢對象,封裝來自前台的幾個輸入框中的值.
查詢對象所有屬性初始化為空串即String str="";
重置查詢對象各屬性的setter方法.示例如下:
public class QureyStr{
String name="";
public void setName(String name){
if(name==null){
this.name="";
}else{
this.name=name;
}
}
}
以上就避免了屬性name=null.
⑻ JSP中怎麼判斷一個從資料庫取出來的值為空的方法
if(取出的值=NULl)then
⑼ jsp判斷字元串是否為空的方式
pass==null 說明pass對象只被聲明引用,並未在堆內存中實例化此對象,這就好比你知道裝水需要容器,但是你現在無容器。而pass==「」,說明此對象已經被實例化,即,裝水的容器你已經拿到手,但是現在容器是空的。
⑽ jsp頁面上做非空判斷
jsp頁面的非空判斷一般由js判斷,判斷方法有多種。
1、js獲取對應輸入框的值value
2、直接利用value==''判斷是否非空或者利用正則表達式校驗value
3、value為空彈出提示給用戶
示例:
頁面有如下輸入框:
<input type="text" id="name" value=""/>
判斷方法:
functionvalidEmpty(){
//獲取輸入框的輸入值
varname=document.getElementById('name').value;
if(name==null||name==''){
alert("username不可為空");
returnfalse;
}
//用正則判斷,至少要輸入一個非空字元
varregex=/^S+$/g;
if(!name.test(regex)){
alert("username不可為空");
returnfalse;
}
}