
你没选择的话,
String[] classid = requestgetParameterValues("ckbox");
所以 classid 是null
本身是没问题的,
但是for(int i=0;i<classidlength;i++)
在这里, 你取了一个空数组的length,
这个对象是空的,
你对他取length,
java会报空指针异常的·······
你好!——
首先,你的提问很有意思。大概是不是指如果在Servlet或Action里接受页面textbox元素的值?
textbox 控件是可复选的。
Servlet:String[] array = requestgetParameterValues("elementName");
Action:String[] array //实现getter and setter即可,Struts2自动将值注入Action对应的属性。
这个控件我也用过
下面是我修改过的代码 我能测试通过
主要修改的地方是 获取对象元素的方法由name改成id
////////////////////下面代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 40 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META name="keywords" content="控件,按钮,年份,相关内容,为空">
<META name="description" content="你没选择的话,String[] classid = requestgetParameterValues("ckbox");所以 classid 是null本身是没问题的,但是for(int i=0;i<classi">
<script>
var myC_x,myC_y;
var myC_timeset=null,myC_timeset1=null;
var divObj=null;
var inputName;
function myCalendar() //构建对象
{
var myDate = new Date();
thisyear = myDategetFullYear();
thismonth = myDategetMonth()+1;
thisdate = myDategetDate();
thisformat="yyyy-mm-dd";
thisstyle = myStyle(1);
thisshow = createCalendar;
thisinput = createInput;
}
function myStyle(num) //设置样式
{
if(!num||isNaN(num)){alert('参数不对,采用默认样式!');num=1;}
var style = new Array();
style[1]="week{background-color:#DfDfff;font-size:12px;width:140px;}"
+"ds{width:140px;font-size:12px;cursor:hand}"
+"mover{border:1px solid black;background-color:#f4f4f4;}"
+"move1{border:1px solid #5d5d5d;background-color:#f4f4f4;color:#909eff;font-size:12px}"
+"tit{background-color:#909EFF;width:140px;font-size:12px;color:white;cursor:default}"
+"cs{position:absolute;border:1px solid #909eff;width:142px;left:0px;top:0px;z-index:9999;}"
+"shadow{position:absolute;left:0px;top:0px;font-family: Arial Black;font-size:50px;color:#d4d4d4;z-index:1;text-align:center;}";
documentwrite("<style type='text/css'>");
documentwrite(style[num]);
documentwrite("</style>");
}
function createCalendar()
{
var week = new Array('日','一','二','三','四','五','六');
documentwrite("<div class='cs' onselectstart='return false' oncontextmenu='return false' onmousedown='if(eventbutton==2)thisstyledisplay=\"none\"' id='myC_div'><div class='shadow'></div><div style='position:absolute;left:0px;top:0px;z-index:1'>");
//创建头部
documentwrite("<table class='tit' id='myC_Top' onmousedown='myC_x=eventx-parentNodeparentNodestylepixelLeft;myC_y=eventy-parentNodeparentNodestylepixelTop;setCapture()' onmouseup='releaseCapture();' onmousemove='myCMove(thisparentElementparentElement);'><tr><td width=10 onmouseover='thisstylecolor=\"black\"' onmouseout='thisstylecolor=\"\"' onclick='cutYear()' style='font-family: Webdings;cursor:hand;' title='减少年份'>7</td><td title='减少月份' onmouseover='thisstylecolor=\"black\"' onclick='cutMonth()' onmouseout='thisstylecolor=\"\"' width=10 style='font-family: Webdings;cursor:hand;'>3</td><td align=center onmouseover=thisclassName='move1'; onmouseout=thisclassName='';divHidden(myCparentElementnextSibling); onclick='createyear("+thisyear+",this);divShow(myCparentElementnextSibling);'></td><td align=center onclick='createmonth("+thismonth+",this);divShow(myCparentElementnextSibling)' onmouseover=thisclassName='move1'; onmouseout=thisclassName='';divHidden(myCparentElementnextSibling);></td><td width=10 onmouseover='thisstylecolor=\"black\"' onmouseout='thisstylecolor=\"\"' onclick='addMonth()' style='font-family: Webdings;cursor:hand;' title='增加月份'>4</td><td width=10 style='font-family: Webdings;cursor:hand;' onmouseover='thisstylecolor=\"black\"' onmouseout='thisstylecolor=\"\"' onclick='addYear()' title='增加年份'>8</td></tr></table>");
//创建星期条目
documentwrite("<table class='week'><tr>");
for(i=0;i<7;i++)
documentwrite("<td align=center>"+week[i]+"</td>");
documentwrite("</tr></table>");
//创建日期条目
documentwrite("<table class='ds' id='myC' cellspacing=2 cellpadding=0>");
for(i=0;i<6;i++)
{
documentwrite("<tr>");
for(j=0;j<7;j++)
documentwrite("<td width=10% height=16 align=center onmouseover='mOver(this)' onmouseout='mOut(this)' onclick='if(thisinnerText!=\"\")getValue(inputName,thisinnerText);myC_divstyledisplay=\"none\"'></td>");
documentwrite("</tr>");
}
documentwrite("</table>");
//建建水印
documentwrite("</div>");
//创建选择图层
documentwrite("<div style='position:absolute;left:0px;top:0px;z-index:3' onmouseover=divShow(this) onmouseout=divHidden(this)></div>");
documentwrite("</div>");
//显示日期
showDate(thisyear,thismonth);
myC_divstyledisplay='none';
}
function getValue(obj,value)
{
var tonylinzhen=documentgetElementById(obj);
tonylinzhenvalue=parseInt(myC_Topcells[2]innerText)+"-"+parseInt(myC_Topcells[3]innerText)+"-"+value;
}
function showDate(year,month)
{
var myDate = new Date(year,month-1,1);
var today = new Date();
var day = myDategetDay();
var length = new Array(31,30,31,30,31,30,31,31,30,31,30,31);
length[1] = ((year%4==0)&&(year%100!=0)||(year%400==0))29:28;
for(i=0;i<myCcellslength;i++)myCcells[i]innerHTML = "";
for(i=0;i<length[month-1];i++)
{
myCcells[i+day]innerHTML = (i+1);
if(new Date(year,month-1,i+1)getDay()==6||new Date(year,month-1,i+1)getDay()==0){myCcells[i+day]stylecolor='red';}
}
myC_Topcells[2]innerText=year+"年";
myC_Topcells[3]innerText=month+"月";
with(myCparentNodepreviousSiblingstyle)
{
pixelLeft=myCoffsetLeft;
pixelTop=myCoffsetTop;
height = myCclientHeight;
width = myCclientWidth;
}
myCparentElementparentElementstyleheight=myCparentElementoffsetHeight;
myCparentElementpreviousSiblinginnerHTML=year;
}
//一些附加函数--------------------
//---------Begin-------------------
function mOver(obj){objclassName = 'mover';}
function mOut(obj){if(objclassName=='mover')objclassName = '';}
function addYear(){var year = parseInt(myC_Topcells[2]innerText);var month = parseInt(myC_Topcells[3]innerText); year++;showDate(year,month);}
function addMonth(){var year = parseInt(myC_Topcells[2]innerText);var month = parseInt(myC_Topcells[3]innerText);month++;if(month>12){month=1;year++;}showDate(year,month);}
function cutYear(){var year = parseInt(myC_Topcells[2]innerText);var month = parseInt(myC_Topcells[3]innerText);year--;showDate(year,month);}
function cutMonth(){var year = parseInt(myC_Topcells[2]innerText);var month = parseInt(myC_Topcells[3]innerText);month--;if(month<1){month=12;year--;}showDate(year,month);}
function divS(obj)
{
if(obj!=divObj)
{
objstylebackgroundColor="#909eff";
objstylecolor='black';
}
if(divObj!=null)
{
divObjstylebackgroundColor='';
divObjstylecolor='';
}
divObj = obj;
}
function divShow(obj)
{ if (myC_timeset!=null) clearTimeout(myC_timeset);
objstyledisplay='block';
}
function divHidden(obj){myC_timeset=windowsetTimeout(function(){objstyledisplay='none'},500);}
function createyear(year,obj)//创建年份选择
{
var ystr;
var oDiv;
ystr="<table class='move1' cellspacing=0 cellpadding=2 width="+objoffsetWidth+">";
ystr+="<tr><td style='cursor:hand' onclick='createyear("+(year-20)+",myC_Topcells[2])' align=center>上翻</td></tr>";
for(i=year-10;i<year+10;i++)
if(year==i)
ystr+="<tr style='background-color:#909eff'><td style='color:black;height:16px;cursor:hand' align=center onclick='myC_Topcells[2]innerText=thisinnerText;showDate("+i+",parseInt(myC_Topcells[3]innerText));myCparentElementnextSiblinginnerHTML=\"\"'>"+i+"年</td></tr>";
else
ystr+="<tr><td align=center style='cursor:hand' onmouseover=divS(this) onclick='myC_Topcells[2]innerText=thisinnerText;showDate("+i+",parseInt(myC_Topcells[3]innerText));myCparentElementnextSiblinginnerHTML=\"\"'>"+i+"年</td></tr>";
ystr+="<tr><td style='cursor:hand' onclick='createyear("+(year+20)+",myC_Topcells[2])' align=center>下翻</td></tr>";
ystr+="</table>";
oDiv = myCparentElementnextSibling;
oDivinnerHTML='';
oDivinnerHTML = ystr;
showDiv(oDiv,objoffsetTop+objoffsetHeight,objoffsetLeft);
}
function createmonth(month,obj)//创建月份选择
{
var mstr;
var oDiv;
mstr="<table class='move1' cellspacing=0 cellpadding=2 width="+(objoffsetWidth+5)+">";
for(i=1;i<13;i++)
if (month==i)
mstr+="<tr style='background-color:#909eff'><td style='color:black;height:16px;cursor:hand' align=center onclick='myC_Topcells[3]innerText=thisinnerText;showDate(parseInt(myC_Topcells[2]innerText),"+i+");myCparentElementnextSiblinginnerHTML=\"\"'>"+i+"月</td></tr>";
else
mstr+="<tr><td align=center style='cursor:hand' onmouseover='divS(this)' onclick='myC_Topcells[3]innerText=thisinnerText;showDate(parseInt(myC_Topcells[2]innerText),"+i+");myCparentElementnextSiblinginnerHTML=\"\"'>"+i+"月</td></tr>";
mstr+="</table>";
oDiv = myCparentElementnextSibling;
oDivinnerHTML='';
oDivinnerHTML = mstr;
showDiv(oDiv,objoffsetTop+objoffsetHeight,objoffsetLeft);
}
function showDiv(obj,top,left)
{
objstylepixelTop=top;
objstylepixelLeft=left;
}
function myCMove(obj)
{
if(eventbutton==1)
{
var X = objclientLeft;
var Y = objclientTop;
objstylepixelLeft= X+(eventx-myC_x);
objstylepixelTop= Y+(eventy-myC_y);
windowstatus=myC_y;
}
}
function showDiv2(obj)
{
inputName=objid;
var e=obj;
var ot = objoffsetTop;
var ol=objoffsetLeft;
while(obj=objparentElement){ot+=objoffsetTop;ol+=objoffsetLeft;}
myC_divstylepixelTop=ot+eoffsetHeight;
myC_divstylepixelLeft=ol;
myC_divstyledisplay="block";
}
function createInput(name)
{myC_divstyledisplay='none';
documentwrite("<input type='text' id='"+name+"' size=20 onfocus='showDiv2(this)'>");
}
// --------------End ---------------------
</script>
<script>
var myCalendar=new myCalendar;
myCalendaryear=2009;
myCalendarshow();
myCalendarinput("txt1");
</script>
</HEAD>
<BODY>
<form>
<input type="text" id="test" onfocus="showDiv2(this)" readonly=true>
</form>
</BODY>
</HTML>
<input type="button" name="check" value="check"/>--->查询<input type="button" name="update" value="update"/>--->更新在servlet中通过String type = requestgetParameter("name")获取,然后判断。
//声名两个单选按钮
private JRadioButton male;
private JRadioButton female;
//初始化按钮,男为默认选中
male = new JRadioButton("男", true);
female = new JRadioButton("女");
//将两个按钮放到同一个组中
ButtonGroup group = new ButtonGroup();
groupadd(male);
groupadd(female);
//在actionPerformed()中获得按钮的选择值
DefaultButtonModel model = (DefaultButtonModel) malegetModel();
if (modelgetGroup()isSelected(model))
//男被选中的处理
else
//女被选中的处理
我觉得 你可以这样 实现。 这样接受传过来的 参数
<% String id= requestgetParameterNames(“id”);
%>
然后下面 是js代码赋值。
o = documentgetElementById("select3"); for(i=0;i<olength;i++){ if(ooptions[i]selected){ alert(ooptions[i]value); } }
以上就是关于jsp中,控件checkbox为空取值问题!!!急全部的内容,包括:jsp中,控件checkbox为空取值问题!!!急、JSP中如何获得textbox的值,然后传给JSP或Action,我用的是Struts2、jsp表单得不到js日历控件的返回值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)