• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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