A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
JSP
Author
problem in accessing the hidden variable from a jsp page.
rammie singh
Ranch Hand
Joined: Mar 26, 2009
Posts: 116
posted
Jun 16, 2009 01:49:49
0
Hi every body.
i am having problem in accesing a hidden variable from a jsp page.
my problem description is
i have a hidden variable
"statusHidn"
in my jsp page.
<input type="hidden" name="statusHidn" value="">
i am appending int values of an array into it through javascript function.
the function is as below
function submitForm() { alert("Hi"); var table=document.getElementById('tbl_thumbRule'); var rowsLength=table.rows.length; alert("rowlength = "+rowsLength); // making all the index value 0 which are untouched. for(i=0;i<rowsLength-1;i++) { if(document.thumbRuleForm.thumbRuleHiddenStatus[i].value=="") { document.thumbRuleForm.thumbRuleHiddenStatus[i].value=0; } } var lengthHiddenStatusArray=document.thumbRuleForm.thumbRuleHiddenStatus.length; var statusHidnPush=""; for(i=0;i<lengthHiddenStatusArray;i++) { statusHidnPush = statusHidnPush + document.thumbRuleForm.thumbRuleHiddenStatus[i].value + ":"; } document.thumbRuleForm.statusHidn.value = statusHidnPush; /* assigning the string(which consists of integers) to hidden variable */ }
now i am trying to access this variable in my
servlet
as
String statusHidn=null; int[] status=null; { if(!(request.getParameter("statusHidn").equals(""))) { System.out.println("to print hidden status"); statusHidn=request.getParameter("statusHidn").toString(); System.out.println("hidden status is " + statusHidn); } if(statusHidn!=null) { String[] statusArray=null; statusArray=statusHidn.split(":");// for(int i=0;i<statusArray.length;i++) { int statusInt=Integer.parseInt(statusArray[i]); System.out.println("after assigning "); System.out.println("statusInt value is " + statusInt); [b]status[i]=statusInt;[/b] // [b]giving null pointer exception at this line of code.[/b] System.out.println("status values are " + status[i] ); // [b]this line is not getting printed[/b] } } }
it is giving null pointer exception when i am trying to assign
status[i]=statusInt;
may be there is some problem of
String
to int conversion. i tried lot's of things but still exception error is coming.
can any body help me please in finding what is the reason for this and what could be the solution.
Thanks and Regards.
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Jun 16, 2009 06:23:32
0
Because the status array is null--you never assign it to anything.
rammie singh
Ranch Hand
Joined: Mar 26, 2009
Posts: 116
posted
Jun 16, 2009 07:29:28
0
hi
initially status[] would be null only.
so what is the solution for this??
Thanks and Regards.
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
I like...
posted
Jun 16, 2009 07:36:03
0
rammie singh wrote:
so what is the solution for this??
you need to initialize right?. or use
ArrayList
. but dont use like below
ArrayList<Object> arrayList = null; arrayList.add("your value");
I agree. Here's the link:
http://aspose.com/file-tools
subject: problem in accessing the hidden variable from a jsp page.
Similar Threads
How to pass input values to the JSP using POST method
unable to access the values of dynamically newly added rows to table
Comparing values using JSTL
resultset is not working properly
How to pass input values to the JSP using POST method
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter