princehyderabad
asked on
How to separate values in getParamaters
Hello,
I have a form and a drop down list...
<form action="Servlet">
<select size="1" name="family">
out.print("<option>"+rs.ge tString(1) +"--"+rs.g etString(2 )+"</optio n>");
</select>
</form>
Now my Servlet accepts all form values.....
But since drop down values contains 2 values ie "rs.getString(1)" and "rs.getString(2)"
How should I separate this 2 values in my serlvet and assign to a string.
My Servlet:
.....
String soft = request.getParameter("fami ly");
String s, p;
s = ??? HOW TO GET VALUES OF rs.getString(1); HERE ????
p =??? HOW TO GET VALUES OF rs.getString(2); HERE ????
<... making DB connection and calling Stored Procedure...>
cs0.setString(1,s);
cs0.setString(2,p);
rEGARDS
I have a form and a drop down list...
<form action="Servlet">
<select size="1" name="family">
out.print("<option>"+rs.ge
</select>
</form>
Now my Servlet accepts all form values.....
But since drop down values contains 2 values ie "rs.getString(1)" and "rs.getString(2)"
How should I separate this 2 values in my serlvet and assign to a string.
My Servlet:
.....
String soft = request.getParameter("fami
String s, p;
s = ??? HOW TO GET VALUES OF rs.getString(1); HERE ????
p =??? HOW TO GET VALUES OF rs.getString(2); HERE ????
<... making DB connection and calling Stored Procedure...>
cs0.setString(1,s);
cs0.setString(2,p);
rEGARDS
ASKER
I mean how to split this whole string which I'm getting in form
String soft = request.getParameter("fami ly");
String[] s = soft.split("--");//hoping you string is like this "price--hyderabad";
s = s[0]
p =s[1]
String[] s = soft.split("--");//hoping you string is like this "price--hyderabad";
s = s[0]
p =s[1]
ASKER
Actually like this:
<option>"+ procResult.getString(1) +" ("+ procResult.getString(2) +")</option>
Prince (Hyderabad)
1st word followed by two spaces " " followed by "(" and 2nd word followed by ")"
<option>"+ procResult.getString(1) +" ("+ procResult.getString(2) +")</option>
Prince (Hyderabad)
1st word followed by two spaces " " followed by "(" and 2nd word followed by ")"
String soft = request.getParameter("fami ly");
String[] s = soft.split("\\W+");//hopin g you string is like this "price ("hyderabad")";
s = s[0]
p =s[1]
String[] s = soft.split("\\W+");//hopin
s = s[0]
p =s[1]
ASKER
I already treid it but not working.
Your above code worked but that is not values really look like.
Let me give you the sample values I may get from DB.
===========
Family Versions
===========
BIG B Version 1.0
BIG IP Version 2.0
--------------------------
And I'm display it in HTML this way.
BIG B (Version 1.0)
BIG IP (Version 2.0)
Something like this, where "BIG B" is 1st string, and "Version 1.0" is 2nd string.
Please suggest me the suitable way.
Your above code worked but that is not values really look like.
Let me give you the sample values I may get from DB.
===========
Family Versions
===========
BIG B Version 1.0
BIG IP Version 2.0
--------------------------
And I'm display it in HTML this way.
BIG B (Version 1.0)
BIG IP (Version 2.0)
Something like this, where "BIG B" is 1st string, and "Version 1.0" is 2nd string.
Please suggest me the suitable way.
There will certainly be a better way than this .I wil let you know if i come across.Check if this work till that time.
Hoping Strin is of the form BIG B ("Version 1.0")
String[] p = s.split("\\(\\"");
System.out.println(p[0]);
String[] q = p[1].split("\\"\\)");
System.out.println(q[0]);
Hoping Strin is of the form BIG B ("Version 1.0")
String[] p = s.split("\\(\\"");
System.out.println(p[0]);
String[] q = p[1].split("\\"\\)");
System.out.println(q[0]);
ASKER
Errors on this line:
String[] q = p[1].split("\\"\\)");
I treid differ "" to remove ....
Error: excepted ; or )
String[] q = p[1].split("\\"\\)");
I treid differ "" to remove ....
Error: excepted ; or )
if you will always have "(" before the second value starts that this shd work..
String[] p = s.split("(");
System.out.println(p[0]);
System.our.println(p[1].su bString(0, p[1].lengt h()-1);
String[] p = s.split("(");
System.out.println(p[0]);
System.our.println(p[1].su
Ok try this
Hoping Strin is of the form BIG B ("Version 1.0")
String[] p = s.split("\\(\"");
System.out.println(p[0]);
String[] q = p[1].split("\"\\)");
System.out.println(q[0]);
Hoping Strin is of the form BIG B ("Version 1.0")
String[] p = s.split("\\(\"");
System.out.println(p[0]);
String[] q = p[1].split("\"\\)");
System.out.println(q[0]);
StringTokenizer stok = new StringTokenizer(soft , "--");
String first=sTok.nextToken();
String second=sTok.nextToken();
String first=sTok.nextToken();
String second=sTok.nextToken();
ASKER
Didnt worked for both Kuldeepchaturvedi and koppcha last posting.
karanw my seperator is not "--" its something like this "BIG B (Version 1.0)"
Thought I'm runing my code temporary using "--" as seperator but I need to know the above solution.
karanw my seperator is not "--" its something like this "BIG B (Version 1.0)"
Thought I'm runing my code temporary using "--" as seperator but I need to know the above solution.
what is the output you are getting from my solution??
ASKER
If this is the value BIG B (Version 1.0)
I'm getting same value BIG B (Version 1.0)
I'm getting same value BIG B (Version 1.0)
You said your output is something like this right BIG B ("Version 1.0")
Isn't it?
If this is the case BIG B (Version 1.0)
then try
String[] p = s.split("\\(");
System.out.println(p[0]);
String[] q = p[1].split("\\)");
System.out.println(q[0]);
Isn't it?
If this is the case BIG B (Version 1.0)
then try
String[] p = s.split("\\(");
System.out.println(p[0]);
String[] q = p[1].split("\\)");
System.out.println(q[0]);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I agree your example is working no doubt.
But here is my value settings:
out.print("<option>"+procR esult.getS tring(1)+" &nbs p;("+procR esult.getS tring(2)+" )</option> ");
BIG B(space)(space)(Bracket)Ve rsion 1.0(Bracket)
or
BIG B (Version 1.0)
Where BIG B is one value and Version 1.0 is other value.
But here is my value settings:
out.print("<option>"+procR
BIG B(space)(space)(Bracket)Ve
or
BIG B (Version 1.0)
Where BIG B is one value and Version 1.0 is other value.
>BIG B(space)(space)(Bracket)Ve rsion 1.0(Bracket)
My earlier example works for this pattern ...Please post the output you are getting
My earlier example works for this pattern ...Please post the output you are getting
ASKER
my mistake.... sorry !! IT WORKED ..
Thanks ;o)
Thanks ;o)
>But since drop down values contains 2 values
What does this mean? you can select multiple values from the drop down box ? or dropdown box has one selection "--" seperated?