• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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
0
princehyderabad
Asked:
princehyderabad
  • 8
  • 8
  • 2
  • +1
1 Solution
 
koppchaCommented:
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?
0
 
princehyderabadAuthor Commented:
I mean how to split this whole string which I'm getting in form
0
 
koppchaCommented:
String soft = request.getParameter("family");
String[] s = soft.split("--");//hoping you string is like this "price--hyderabad";
s = s[0]
p =s[1]

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
princehyderabadAuthor Commented:
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 ")"
0
 
koppchaCommented:
String soft = request.getParameter("family");
String[] s = soft.split("\\W+");//hoping you string is like this "price  ("hyderabad")";
s = s[0]
p =s[1]
0
 
princehyderabadAuthor Commented:
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.
0
 
koppchaCommented:
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]);
0
 
princehyderabadAuthor Commented:
Errors on this line:
String[] q = p[1].split("\\"\\)");

I treid differ "" to remove ....
Error: excepted ; or )
0
 
KuldeepchaturvediCommented:
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);
0
 
koppchaCommented:
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]);
0
 
ManishLeadCommented:
StringTokenizer stok = new StringTokenizer(soft , "--");
String first=sTok.nextToken();
String second=sTok.nextToken();
0
 
princehyderabadAuthor Commented:
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.
0
 
KuldeepchaturvediCommented:
what is the output you are getting from my solution??
0
 
princehyderabadAuthor Commented:
If this is the value BIG B (Version 1.0)

I'm getting same value BIG B (Version 1.0)
0
 
koppchaCommented:
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]);
0
 
koppchaCommented:
This short program works fine...

import java.util.*;
import java.io.*;
public class StringProcessor
{
public static void main(String[] args)
{
String s ="BIG B (Version 1.0)";
String[] p = s.split("\\(");
System.out.println(p[0]);
String[] q = p[1].split("\\)");
System.out.println(q[0]);
}
}
0
 
princehyderabadAuthor Commented:
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.
0
 
koppchaCommented:
>BIG B(space)(space)(Bracket)Version 1.0(Bracket)
   My earlier example works for this pattern ...Please post the output you are getting
0
 
princehyderabadAuthor Commented:
my mistake.... sorry !! IT WORKED ..

Thanks ;o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 8
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now