Link to home
Start Free TrialLog in
Avatar of princehyderabad
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.getString(1)+"--"+rs.getString(2)+"</option>");
 </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("family");
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
Avatar of koppcha
koppcha
Flag of United States of America image

you can get it as one whole string and split it.
>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?
Avatar of princehyderabad
princehyderabad

ASKER

I mean how to split this whole string which I'm getting in form
String soft = request.getParameter("family");
String[] s = soft.split("--");//hoping you string is like this "price--hyderabad";
s = s[0]
p =s[1]

Actually like this:

<option>"+ procResult.getString(1) +"&nbsp;&nbsp;("+ procResult.getString(2) +")</option>

Prince  (Hyderabad)

1st word followed by two spaces "&nbsp;&nbsp;" followed by "(" and 2nd word followed by ")"
String soft = request.getParameter("family");
String[] s = soft.split("\\W+");//hoping you string is like this "price  ("hyderabad")";
s = s[0]
p =s[1]
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.
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]);
Errors on this line:
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].subString(0,p[1].length()-1);
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]);
Avatar of Manish
StringTokenizer stok = new StringTokenizer(soft , "--");
String first=sTok.nextToken();
String second=sTok.nextToken();
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.
what is the output you are getting from my solution??
If this is the 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]);
ASKER CERTIFIED SOLUTION
Avatar of koppcha
koppcha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree your example is working no doubt.

But here is my value settings:
out.print("<option>"+procResult.getString(1)+"&nbsp;&nbsp;("+procResult.getString(2)+")</option>");

BIG B(space)(space)(Bracket)Version 1.0(Bracket)
or
BIG B&nbsp;&nbsp;(Version 1.0)

Where BIG B is one value and Version 1.0 is other value.
>BIG B(space)(space)(Bracket)Version 1.0(Bracket)
   My earlier example works for this pattern ...Please post the output you are getting
my mistake.... sorry !! IT WORKED ..

Thanks ;o)