wood burning stoves 2.0*
The moose likes JSP and the fly likes unable to get the output in required format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "unable to get the output in required format" Watch "unable to get the output in required format" New topic
Author

unable to get the output in required format

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
i had a doubt that the output should come like 'F,10:'..but i m getting as 'F,10'..i tried so many times..i m not getting can any one suggest me where the code gets wrong...here i m sending jsp code,javascript code and servlet code..can anyone check it..i m waiting for the reply...its urgent.

login.jsp



login.js



login.java



Thanks and waiting for the reply,
madhu.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42372
    
  64
Having different input types (like text and checkbox) with the same name is a bug waiting to happen. Why don't they have distinctive names?

Also, the servlet code doesn't make sense - both branches of the if statement do the same thing (although it probably doesn't matter, because the "if" branch will never be executed, since "balrdysStr" is never null).


Ping & DNS - my free Android networking tools app
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
'F,10:'..but i m getting as 'F,10'

you need : at end ??
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
yes i need
:
at the end of
F,10
..can you help me out regarding this matter...

Thanks in advance,
madhu
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230



you can append it ":" naa after reading the value in bean .

value = value+":" ;

getting or not ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42372
    
  64
I see no colon in the code you posted; where do you expect it to come from?
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
Dear Madhu,
You are retieving values
like this ok ?

String[] balrdys = request.getParameterValues("balrdys");

so iterate this loop

for(int i=0;i<balrdys .length;i++)
{

String days=(balrdys[i]).append(":");
}

check this out let me know >
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i had done it previously..i m getting wrong output..not the required out..here is my output code..

output:


login.jsp



login.java



i need to get the output as



can you provide me the solution for this...waiting for the reply..
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
ya where is your cubicle

Added check

String[] balrdys = request.getParameterValues("balrdys");
String balrdysStr = "";
for (int i = 0; i < balrdys.length; i++) {
if (balrdysStr == null) {
balrdysStr += balrdys[i];
} else {
balrdysStr += balrdys[i];
//added by Ravi
if(i<balrdys.length-1)
{
balrdysStr = balrdysStr +":";
}
}
}

check this out >
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42372
    
  64
Again:
Having different input types (like text and checkbox) with the same name is a bug waiting to happen. Why don't they have distinctive names?

Also, the servlet code doesn't make sense - the "if" branch will never be executed, since "balrdysStr" is never null.
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
no i don't this so , she is expecting output as F,10: how will she get desired output with out appending ":" at end of value
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi good morning,
i tried what you had given..i m getting same wrong output not the correct output...down i m giving the output..is there any method to get the correct output..i tried so many ways unable to get it...



thanks,
madhu
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Good morning.

I'd like to point out that :
1. You should read carefully what Ulf is telling you.
2. You need to describe your needs clearly, what you are expecting, and how you are expecting it to happen. I think it's useless to throw you semi-colons without understanding your needs. I still have no clue about that semi-colon you're dying to see in the output. For example:
"I click the checkbox whose value is "F," and enter "10" in the textbox. After submitting, I expect that the logic which retrieves the ""balrdys" values will result in "F,10:". I have to append the selected checkbox value, the entered text, and finally append a semi-colon to it". Something like that.

So... what do you really want to achieve ?


[My Blog]
All roads lead to JavaRanch
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
what you had replied is correct...if i click checkbox and if i enter the value in textbox both should be appended after submit button and the answer what i need is 'F,10:'
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Ok. I'm still guessing :
If you select "F,", you want the Fresh Activation text appended to it ? -> "F,10:"
If you select "A,", you want the Auto-Renewal text appended to it ? -> "A,20:"
If you select both "F," and "A," -> "F,10,A,20:"
Is this something like this ? What about the "NO" checkbox ?
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
HI ........ its as simple as dat ...Madhu why dont you try what i am saying ...........
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61456
    
  67

"dat"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
Its short hand notation for that.
while sending text from mobile we use that kind of short cuts ;)
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Christope,

what you are guessing is rite...



i need the output like that..

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi ravindra,
good morning...i tried what you suggested i m not getting the correct output..here with i m sending the code...

ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
what are you getting now ?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i m getting the output as

<LOW_DAYS>F,:10:</LOW_DAYS>
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
HI Madhu,

I trid what code you have given ,ok

you have 3 checkboxes , one with value No and other twos having input type as text,
so you are geeting 3 values two in nuber of days and one as No

so better you modify the code like this


<td><input type="checkbox" name="chk_Fbalrdys" value="F,"id="chkA">Fresh Activation <input type="text" name="Fbalrdys" size="1" id="txtA"/>

<input type="checkbox" name="Chk_Abalrdys" value="A,">Auto-Renewal <input type="text" name="Abalrdys" size="1">

<input type="checkbox" name="Chk_Nbalrdys" value="NO">No



and in bean read values like this


tring _Fdays = request.getParameter("Fbalrdys");
String _Adays request.getParameter("Abalrdys");

if(_Fdays!=null )
{
_Fdays=_Fdays.append(":")
}

if(_Adays! null)

{
_Adays=_Adays.append(":")
}



hope this will work ....

Are you from which company ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

As Ulf said (please read his posts!!), giving the same name to all your components is not a good idea. Looping through the values returned by getParameterValues will give you unpredictable results. Why don't you give each component its own name, and get each values one by one ? You'll easily get the result you want by doing so.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi ravindra,
i tried its not getting... the output i got is

<LOW_DAYS>10::</LOW_DAYS>
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
Slight change

i have not used checkbox values that is F,


so in bean use

tring _Fdays = request.getParameter("Fbalrdys");
String _Adays request.getParameter("Abalrdys");

if(_Fdays!=null )
{
_Fdays= "F,"+_Fdays.append(":")
}

if(_Adays! null)

{
_Adays="A,"+_Adays.append(":")
}

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Instead of trying to give a complete solution, I think it would be better to leave madhuri try to understand where the problem is, and let him update his code after reading our recommendations.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi ravindra,
i got it...thanks for your support...my doubt was not still clarified...i m developing web-application...using jsp page i need to develop XML file...i created..i used what you suggested in my code...the problem is i m getting 2 times the element..i.e.,

<LOW_DAYS>F,10::</LOW_DAYS>
<LOW_DAYS>A,10:::</LOW_DAYS>

but i need is <LOW_DAYS>F,10:A,11:</LOW_DAYS>

how can i get that..
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
Will you please update me with the code you are using to create xml
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
login.js




login.java

ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
I havent worked on xml

but still modified the code combine A days and F days under Low Days tag ...

Element balrdysElement = doc.createElement("DAYS");
subchild.appendChild(balrdysElement);
Element balrdysElement1 = doc.createElement("LOW_DAYS")
Text balrdysElementText = doc.createTextNode(_Fdays+_Adays);
balrdysElement1.appendChild(balrdysElementText);

;
subchild.appendChild(balrdysElement1);
Text balrdysElementText1 = doc.createTextNode(_Adays);
balrdysElement1.appendChild(balrdysElementText1);
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
ok thanks i'll check it..do you have any idea regarding javascript...
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
_/\_ Yes ...go ahead ...you can post it in a new thread.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
the site you had given is not opening....i had created XML file...my doubt is how to do DML operations for XML file...for that i m using jsp page..if i enter the value in textbox it should validate that it is present in XML file or not...i have an idea how to do using Database...but no idea how to check the entered value in XML file..can you suggest me the solution..
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
hmmmm, no you need to read your xml file to do that validation
sting matching operation for stting you are reading with value of your xml file ....

you are wrokining in which company ?
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i didnt got your point i work in IBM..what about you
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
In Pune IBM ? , i am with Geometric ...
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
no from chennai,i need help can you suggest me what to do..its urgent
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

its urgent

EaseUp.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
ravi are you there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to get the output in required format