急,急!!一个jsp问题!!!!顺便再问一下求当天的日期函数! (50分)

  • 主题发起人 主题发起人 雨林^-^
  • 开始时间 开始时间

雨林^-^

Unregistered / Unconfirmed
GUEST, unregistred user!
现在有一个多选框
<SELECT multiple name=city size=5 style="WIDTH: 150px">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</SELECT>
提交后如何用jsp把里面的值全部抓出来,抓出来后变成一个字符串如:"1,2,3"
很急呀,望高手帮忙!
顺便再问一下求当天的日期函数!
格式如"2004-6-2"
 
<%
String citystr=",";
String[] city=request.getParameterValues("city");
for(int i=0;i<city.length;i++){
citystr+=city;
}
%>
 
<%
String citystr="";
String[] city=request.getParameterValues("city");
for(int i=0;i<city.length;i++){
citystr+=city;
if(i!=city.length-1) citystr+=",";
//最后一个数后面不需要加‘,’
}
%>
 
to 怒剑狂生,szzhb
不行呀,出现这样的错误!
Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

root cause
java.lang.NullPointerException
at org.apache.jsp.test3_jsp._jspService(test3_jsp.java:45)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
 
to 怒剑狂生,szzhb
我知道是咋回事了,是要用鼠标选种才行,如果不用鼠标选就会出错!望两位大侠帮帮忙,告诉我不用鼠标选也可以抓出里面的资料!万分感谢!
 
这行
<option value="1">1</option>
改为
<option value="1" selected>1</option>
 
这是我程序的原来码,请各位大侠帮我看一下应该咋改!
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
<title>新建网页 1</title>
<SCRIPT language=JavaScript>
function save_search()
{

if (document.Form1.name.value == "")
{
alert("请输入搜索器的名字,建议每个搜索器不要重名!!!");
return false;
}
else
{ ToGo();
document.Form1.action = "mysave.asp";
document.Form1.submit();
return true;
}
}
</SCRIPT>
<SCRIPT language=JavaScript>
function ToGo()
{
SelectTotal('city');
SelectTotal('position_type');
SelectTotal('company_type');
//window.Form1.action="ti1.asp";
//window.Form1.submit();
}
function SelectTotal(ObjName)
{ ObjID = GetObjID(ObjName);
if (ObjID != -1)
{ for (i=0;
i<document.Form1.elements[ObjID].length;
i++)
do
cument.Form1.elements[ObjID].options.selected = true;
}
}

function GetObjID(ObjName)
{ for ( var ObjID=0;
ObjID < window.Form1.elements.length;
ObjID++ )
if (window.Form1.elements[ObjID].name == ObjName )
{ return(ObjID);
break;
}
return(-1);
}
function IsSelected(ID, Value)
{ if (ID != -1 &amp;&amp;
Value != "")
{ for (var cc=0;
cc<document.Form1.elements[ID].length;
cc++ )
{ if (document.Form1.elements[ID].options[cc].value == Value)
return true;
}
return false;
}
return false;
}
function HasTotal(ID)
{ if (ID != -1 )
{ for (var cc=0;
cc<document.Form1.elements[ID].length;
cc++ )
{ if (do
cument.Form1.elements[ID].options[cc].selected )
{ if (document.Form1.elements[ID].options[cc].value == "0000")
{ return true;
}
}
}
return false;
}
return false;
}
function AppendItem(ObjName, DesName)
{ ObjID = GetObjID(ObjName);
DesObjID = GetObjID(DesName);
if (ObjID != -1 &amp;&amp;
DesObjID != -1)
{ if ( IsSelected(DesObjID, "0000") )
window.alert("已包含");
else
{ if ( HasTotal(ObjID) )
{ do
cument.Form1.elements[DesObjID].length = 0;
do
cument.Form1.elements[DesObjID].options[0]= new Option("---不限---", "0000");
}
else
{ if (document.Form1.elements[DesObjID].length == 5)
window.alert("最多选五项。");
else
{ //GET SELECTED ITEM NUMBER
SelNum = 0;
for (var j=0;
j<document.Form1.elements[ObjID].length;
j++)
{ if (do
cument.Form1.elements[ObjID].options[j].selected)
SelNum ++;
}
if ((SelNum +do
cument.Form1.elements[DesObjID].length) > 5)
window.alert("最多选五项。");
else
{ //add
for (j=0;
j<document.Form1.elements[ObjID].length;
j++)
{ if (document.Form1.elements[ObjID].options[j].selected)
{ //GET VALUE
dd =do
cument.Form1.elements[ObjID].options[j].value;
if (!IsSelected(DesObjID, dd))
{ //GET LENGTH
DesLen =do
cument.Form1.elements[DesObjID].length;
// NEW OPTION
do
cument.Form1.elements[DesObjID].options[DesLen]= new Option(document.Form1.elements[ObjID].options[j].text,do
cument.Form1.elements[ObjID].options[j].value);
}
else
window.alert("此选项已选择。");
}
}
}
}
}
}
//CLEAR
for (j=0;
j<document.Form1.elements[ObjID].length;
j++)
do
cument.Form1.elements[ObjID].options[j].selected = false;
}
}
function RemoveItem(ObjName)
{ ObjID = GetObjID(ObjName);
if ( ObjID != -1 )
{ var check_index = new Array();
for (i=window.Form1.elements[ObjID].length-1;
i>=0;
i--)
{ if (window.Form1.elements[ObjID].options.selected)
{ check_index = true;
window.Form1.elements[ObjID].options.selected = false;
}
else
check_index = false;
}
for (i=window.Form1.elements[ObjID].length-1;
i>=0;
i--)
{ if (check_index)
window.Form1.elements[ObjID].options = null
}
}
}
</SCRIPT>
</head>
<body>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=600>
<TR>
<form method="POST" name="Form1">
<TD align=right vAlign=top><FONT color=#ff3333>*</FONT>工作地点:
<SCRIPT language=javascript>
<!--
function initprovince()
{
province = new Array();
province[0] = new Array();
province[0][0] ='*';
province[0][1] ='--请选择--';
province[1] = new Array();
province[1][0] ='北京';
province[1][1] ='北京';
province[2] = new Array();
province[2][0] ='上海';
province[2][1] ='上海';
province[3] = new Array();
province[3][0] ='天津';
province[3][1] ='天津';
province[4] = new Array();
province[4][0] ='重庆';
province[4][1] ='重庆';
province[5] = new Array();
province[5][0] ='安徽';
province[5][1] ='安徽';
province[6] = new Array();
province[6][0] ='甘肃';
province[6][1] ='甘肃';
province[7] = new Array();
province[7][0] ='福建';
province[7][1] ='福建';
province[8] = new Array();
province[8][0] ='广东';
province[8][1] ='广东';
province[9] = new Array();
province[9][0] ='广西';
province[9][1] ='广西';
province[10] = new Array();
province[10][0] ='贵州';
province[10][1] ='贵州';
province[11] = new Array();
province[11][0] ='海南';
province[11][1] ='海南';
province[12] = new Array();
province[12][0] ='河北';
province[12][1] ='河北';
province[13] = new Array();
province[13][0] ='河南';
province[13][1] ='河南';
province[14] = new Array();
province[14][0] ='黑龙江';
province[14][1] ='黑龙江';
province[15] = new Array();
province[15][0] ='湖北';
province[15][1] ='湖北';
province[16] = new Array();
province[16][0] ='湖南';
province[16][1] ='湖南';
province[17] = new Array();
province[17][0] ='吉林';
province[17][1] ='吉林';
province[18] = new Array();
province[18][0] ='江苏';
province[18][1] ='江苏';
province[19] = new Array();
province[19][0] ='江西';
province[19][1] ='江西';
province[20] = new Array();
province[20][0] ='辽宁';
province[20][1] ='辽宁';
province[21] = new Array();
province[21][0] ='内蒙古';
province[21][1] ='内蒙古';
province[22] = new Array();
province[22][0] ='宁夏';
province[22][1] ='宁夏';
province[23] = new Array();
province[23][0] ='青海';
province[23][1] ='青海';
province[24] = new Array();
province[24][0] ='山东';
province[24][1] ='山东';
province[25] = new Array();
province[25][0] ='山西';
province[25][1] ='山西';
province[26] = new Array();
province[26][0] ='陕西';
province[26][1] ='陕西';
province[27] = new Array();
province[27][0] ='四川';
province[27][1] ='四川';
province[28] = new Array();
province[28][0] ='西藏';
province[28][1] ='西藏';
province[29] = new Array();
province[29][0] ='新疆';
province[29][1] ='新疆';
province[30] = new Array();
province[30][0] ='云南';
province[30][1] ='云南';
province[31] = new Array();
province[31][0] ='浙江';
province[31][1] ='浙江';
province[32] = new Array();
province[32][0] ='香港特别行政区';
province[32][1] ='香港特别行政区';
province[33] = new Array();
province[33][0] ='澳门特别行政区';
province[33][1] ='澳门特别行政区';
province[34] = new Array();
province[34][0] ='台湾';
province[34][1] ='台湾';
}
function initprovinceitem(myfrm,selected)
{
var i
for(i = 0;
i<=province.length-1;
i++)
{
if (province[0] == selected )
document.write('<option value=' + province[0] + ' selected>' + province[1] + '</option>/n');
else
document.write('<option value=' + province[0] + '>' + province[1] + '</option>/n');

}
}
//-->
</SCRIPT>
<SCRIPT language=javascript>
<!--
initprovince();
//-->
</SCRIPT>
</TD>
<TD align=middle><SELECT multiple name=city2 size=5
style="WIDTH: 150px">
<SCRIPT language=javascript>
<!--
initprovinceitem(document.form1,'');
//-->
</SCRIPT>
</SELECT> </TD>
<TD align=middle><INPUT name=Input onclick="JavaScript:AppendItem('city2','city')" type=button value="添加>>">
<BR><BR><INPUT name=Input2 onclick="JavaScript:RemoveItem('city')" type=button value="<<删除">
</TD>
<TD align=middle><SELECT multiple name=city size=5
style="WIDTH: 150px"></SELECT> </TD>
<TD> </TD>
</form>
</TR>
</TABLE>

</body>
</html>
我最后要抓的是city框
 
呵呵,当天日期我已搞定跟大家分享一下
<%
java.util.Date currentTime_1 = new java.util.Date();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
String riqi=formatter.format(currentTime_1);
out.println(riqi);

%>

希望高手能帮我解决上面的问题!再三感谢!
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部