Results 1 to 3 of 3
  1. #1
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Question using the value taken from jsp page

    import java.io.*;
    import java.util.regex.*;

    public class demo2{

    public static void main(String[] args) throws IOException
    {

    String g="14";
    char ch2=g.charAt(0);
    char ch1=g.charAt(1);
    System.out.println(ch2);
    System.out.println(ch1);
    File file1 = new File("prob.txt");
    //StringBuffer contents = new StringBuffer();
    BufferedReader reader = null;
    String text=null;
    try
    {

    reader = new BufferedReader(new FileReader(file1));


    while ((text = reader.readLine()) != null) {
    String []splits1 = text.split(" \\s+." );
    for(int j=0; j< splits1.length ;j++){

    if(splits1[j].length() > 0 )
    {
    //In this line I want to put the value which user select from a jsp page....for ex may user select
    // 1 or 2 0r 3(it is working for number having more than on digit but not fore the digit having only one digit for ex.1,2,3...9
    if(splits1[j].charAt(0) ==ch2 && splits1[j].charAt(1) == ch1)
    {
    System.out.println(splits1[j]);
    int index = splits1[j].indexOf('(');
    int index1 = splits1[j].indexOf(')');
    int index2=index1+1;

    String t = splits1[j].substring(index, index2);
    System.out.println(t);

    int index3 = splits1[j].indexOf('[');
    int index4 = splits1[j].indexOf(']');
    int index5=index4+1;

    String t1 = splits1[j].substring(index3, index5);
    System.out.println(t1);

    }
    }
    }
    }
    }
    catch (FileNotFoundException e)
    {
    e.printStackTrace();
    }
    }
    }
    see da line given :
    if(splits1[j].charAt(0) ==ch2 && splits1[j].charAt(1) == ch1)
    {


    ..its wrkin if digit contain two number ..but not for digit having one number for ex.1,2...9 ...Thanx all..
    Last edited by ras_pari; 10-08-2009 at 07:30 AM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    Don't try to compare individual characters of the string of the number, just compare the string?
    like:

    Java Code:
    String g="14";
    ...
    if(splits1[j].length() > 0 )
    {
    
    // and here, compare the entire string
    if(splits1[j]..equals(g)) {

  3. #3
    ras_pari is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    thanx for ur reply...............now I understand where I was having a problem...Thanx once again..

Similar Threads

  1. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 10:30 AM
  2. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  3. Replies: 21
    Last Post: 08-01-2008, 11:13 AM
  4. warning that page has expired and i need to refresh the page again
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 07-15-2008, 01:48 PM
  5. help with jsp page
    By praveena in forum New To Java
    Replies: 3
    Last Post: 02-05-2008, 11:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •