By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,797 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,797 IT Pros & Developers. It's quick & easy.

posting variables into the same jsp...

P: 4
i am using a 2 jsp's, named first.jsp and details.jsp
when i click on SHOW button of first.jsp, details.jsp must be invoked, this details.jsp has 3 buttons like PREVIOUS, NEXT, and BACK.
BACK is used to redirect my page to first.jsp...
when this page gets loaded there is a int counter=0,
now when i click on NEXT button the same jsp must be invoked but counter valued incremented by 1, and if i click on PREVIOUS, this counter valued decremented by 1.
this counter value goes, searches some data from database and gets the results.

so its kind of a previous & next button concept, but here with a condition that this values should be thrown into the same jsp with the modified counter value, on click of PREVIOUS and NEXT.

i have acheived this with session variable, but when i click on BACK button of details.jsp, this is redirected to first.jsp when i click on SHOW of first.jsp, the value is not initialised to 0, as session does not have that..and the details i am getting as null....

any help is greatly appreciated...
thanks in advance....
Jan 29 '07 #1
Share this Question
Share on Google+
8 Replies


10K+
P: 13,264
i am using a 2 jsp's, named first.jsp and details.jsp
when i click on SHOW button of first.jsp, details.jsp must be invoked, this details.jsp has 3 buttons like PREVIOUS, NEXT, and BACK.
BACK is used to redirect my page to first.jsp...
when this page gets loaded there is a int counter=0,
now when i click on NEXT button the same jsp must be invoked but counter valued incremented by 1, and if i click on PREVIOUS, this counter valued decremented by 1.
this counter value goes, searches some data from database and gets the results.

so its kind of a previous & next button concept, but here with a condition that this values should be thrown into the same jsp with the modified counter value, on click of PREVIOUS and NEXT.

i have acheived this with session variable, but when i click on BACK button of details.jsp, this is redirected to first.jsp when i click on SHOW of first.jsp, the value is not initialised to 0, as session does not have that..and the details i am getting as null....

any help is greatly appreciated...
thanks in advance....
You should put a condition that checks if the variable in the session is null and initializes it to zero. If you do not understand this then post the code for the jsp page that is giving null(make sure you post the code wrapped around tags)
Jan 29 '07 #2

P: 4
thanks for the suggestion....
can u give me the code for what u have said....i guess i am doing that only...

let us assume my page, has a java variable, i am chkng if the session variable is null, then its printing 0, else it should increment to 1. i have a submit button, when i click on this this value must get increment by 1, and another submit button, if this is clicked then this value must be decremented by 1....
i am using this counter variable to get some data from database....

send me some code if u have for the above mentioned...
Jan 30 '07 #3

10K+
P: 13,264
... i am chkng if the session variable is null, then its printing 0...
It should print 0 and set 0 in the session as well.


send me some code if u have for the above mentioned...
It is much better for you to send the code that you have and we can see where the error is.
Jan 30 '07 #4

hirak1984
100+
P: 316
did u make the count "static"?
Jan 30 '07 #5

P: 4
thanks for the replies...

i dont want to use session as when i click on back button and come back to this page, session variable does not hold null...it contains some counter value instead of null.

let me put u this way..whenever the page gets loaded, does the session has the value as null...i think no...

instead of session i want to use request or any other object which fullfills my requirement...so is there any object which does this...

this below code is using session only...may be this code is sytanctically wrong as i have deleted code which is not required.....

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body >
<%
int c=0;
%>
<form name="nextAvailForm" action="availabilityList.jsp">
<center>
<%
try {
Integer count = (Integer) session.getAttribute("count");
//HERE I HAVE DECLARED A COUNT OBJECT, GETTING FROM SESSION, BELOW I AM CHECKIGN WHETHER IT IS NULL, IF NULL THEN MAKE IT AS 0, ELSE IT IS INCREMENTED BY 1
if (count == null) {
count = new Integer(0);
} else {
count = new Integer(count.intValue() + 1);
}
session.setAttribute("count", count);
//HERE I AM SETTING THIS SESSION VARIABLE
for(int k=0;k<availabilityList.size();k++){
CheckAvailability.AvailabilityStatus availabilityStatus = (CheckAvailability.AvailabilityStatus) chkAvailability.getAvailabilityStatusList().get(In teger.parseInt(count.toString()));
//HERE I AM QUERYING TO GET VALUES BASED ON THAT COUNT VALUE....
<%
}
%>
<%
}
}catch(Exception e){
e.printStackTrace();
}
%>
<table border="1" align="right" width="20%">
<tr align="center">
<td align="center">
<input type="submit" id="wizard_ok" name="okButton" value="Accept" class="wizOkBtn" onClick="return checkRadio()">
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="okButton" value="Back" onClick="goBack()" class="wizCnclBtn">
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="okButton" value="Previous" class="wizCnclBtn">
</td>
<td align="center">
<input type="button" id="wizard_ok" name="okButton" value="Next" class="wizOkBtn" onClick='testme()'>
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="cancelButton" value="Cancel" onClick="window.close()" class="wizCnclBtn">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
Jan 30 '07 #6

10K+
P: 13,264
thanks for the replies...

i dont want to use session as when i click on back button and come back to this page, session variable does not hold null...it contains some counter value instead of null.

let me put u this way..whenever the page gets loaded, does the session has the value as null...i think no...

instead of session i want to use request or any other object which fullfills my requirement...so is there any object which does this...

this below code is using session only...may be this code is sytanctically wrong as i have deleted code which is not required.....

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body >
<%
int c=0;
%>
<form name="nextAvailForm" action="availabilityList.jsp">
<center>
<%
try {
Integer count = (Integer) session.getAttribute("count");
//HERE I HAVE DECLARED A COUNT OBJECT, GETTING FROM SESSION, BELOW I AM CHECKIGN WHETHER IT IS NULL, IF NULL THEN MAKE IT AS 0, ELSE IT IS INCREMENTED BY 1
if (count == null) {
count = new Integer(0);
} else {
count = new Integer(count.intValue() + 1);
}
session.setAttribute("count", count);
//HERE I AM SETTING THIS SESSION VARIABLE
for(int k=0;k<availabilityList.size();k++){
CheckAvailability.AvailabilityStatus availabilityStatus = (CheckAvailability.AvailabilityStatus) chkAvailability.getAvailabilityStatusList().get(In teger.parseInt(count.toString()));
//HERE I AM QUERYING TO GET VALUES BASED ON THAT COUNT VALUE....
<%
}
%>
<%
}
}catch(Exception e){
e.printStackTrace();
}
%>
<table border="1" align="right" width="20%">
<tr align="center">
<td align="center">
<input type="submit" id="wizard_ok" name="okButton" value="Accept" class="wizOkBtn" onClick="return checkRadio()">
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="okButton" value="Back" onClick="goBack()" class="wizCnclBtn">
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="okButton" value="Previous" class="wizCnclBtn">
</td>
<td align="center">
<input type="button" id="wizard_ok" name="okButton" value="Next" class="wizOkBtn" onClick='testme()'>
</td>
<td align="center">
<input type="button" id="wizard_cancel" name="cancelButton" value="Cancel" onClick="window.close()" class="wizCnclBtn">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
Yeah you can use request.getAttribute() or request.getParameter. For getParameter you'll need to make the varable a hidden field on the form and increment it using javascript onClick of the link just before submitting.
Jan 30 '07 #7

P: 4
Yeah you can use request.getAttribute() or request.getParameter. For getParameter you'll need to make the varable a hidden field on the form and increment it using javascript onClick of the link just before submitting.
yes but then in that case....that javascript value has to be passed the java code...

how can i acheive this.......

if u have any code do post that...
Jan 30 '07 #8

10K+
P: 13,264
yes but then in that case....that javascript value has to be passed the java code...

how can i acheive this.......

if u have any code do post that...
Something like this:

Expand|Select|Wrap|Line Numbers
  1.  function setValue(form) { 
  2.   form.variable.value =  form.variable.value + 1;
  3.  
  4.  
  5. <FORM name ="whaever" action="something.jsp" onSubmit = "setValue(this)">
  6. <INPUT type ="hidden" name = "variable" value ="">
  7. </Form>
  8.  
  9. String value = request.getParameter("variable");
  10.  
Jan 30 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.