String Trimming Issue

Hello, All.
In one of my JSP's, I retrieve search parameters a user entered on a form add it to the session. I then redisplay the data to the when they return to the JSP. What's happening is that when the data is redisplayed in the text fields, it shows as if there are leading spaces or tabs. I do a string trim before I add the data to the session, but this does not seem to work. I have also tried trimming the string after retrieving the data from the session object.
I have also confirmed that the length of the data item placed in the session is the same as the length of the item once I retrieve it from the session. I'm not sure, but I believe it may be inserting tabs into the text fields. Anyone out there know what's going on? Any assistance is appreciated. Thanks much.

I use the following code to retrieve the data from the html form and run it through my cleanParam method, which just trims it:
String name = cleanParam(request.getParameter("compname"));
I then add the code to the session after I've performed processing on the data:
session.setAttribute("name", name);
The html form has the following code to display data:
<input type="text" name="compname" size="30" maxlength="30" value=
<%if(!isEmptyString(getSessionString(session, "name"))){%>"
<%= session.getAttribute("name") %>"<%}else{%>"<%=name%>"<%}%>>
Thanks.

Similar Messages

  • String.trim() doubt

    Hi,
    why code is comaparing differently ?can you explain me please?
    class TestKing {
    public static void main(String[] args) {
    System.out.println("string".toUpperCase().intern() == "STRING");
    System.out.println("gap1");
    if ("String".trim() == "String".trim())
    System.out.println("Equal");
    else
    System.out.println("Not Equal");
    System.out.println("gap2");
    if("String".toUpperCase() == "String".toUpperCase())
    System.out.println("Equal");
    else
    System.out.println("Not Equal"); // not equa is answere ,why
    output
    true
    gap1
    Equal
    gap2
    Not Equal
    thanks
    ravikumar

    Hi,
    why code is comaparing differently ?can you explain
    me please?
    class TestKing {
    public static void main(String[] args) {
    ystem.out.println("string".toUpperCase().intern() ==
    "STRING");
    System.out.println("gap1");
    if ("String".trim() == "String".trim())
    System.out.println("Equal");
    System.out.println("Not Equal");
    System.out.println("gap2");
    if("String".toUpperCase() ==
    "String".toUpperCase())
    System.out.println("Equal");
    se
    System.out.println("Not Equal");
    // not equa is answere ,why
    output
    true
    gap1
    Equal
    gap2
    Not Equal
    thanks
    ravikumarUse the equals() method to compare two objects. The == operator will only tell you if the contents of two variables are equal.
    Eg.
    "string".equals("string");  //returns trueEDIT: TuringPest beat me to it.
    Message was edited by:
    maple_shaft

  • String.trim() bug...

    In this case String.trim() returns "hello "
    The character it has trouble trimming is known in HTML as & n b p s ;
    Is this a bug? it certainly looks like white space if you ask me.
    public class NoBreakTrimTest {
      public static void main(String[] args) {
        char c = 0x00A0;
        String input = "hello" + c;
        String trimmed = input.trim();
        System.out.println("Trimmed: " + trimmed);
        boolean equal = trimmed.equals("hello");
        System.out.println("Equal: " + equal);
    }

    Err that was a joke ;-)Not completely, no. This sort of thread has a tendency to degenerate quite quickly into a flamewar when the OP won't accept that it isn't a bug. Seems easier to just let them file a bug report and get on with other things!
    OP, if it's a bug, please show us what part of the
    specification of String.trim() is being violated.I'd add to that, "be prepared to reverse your belief in this bug, if it is shown not to be a bug".

  • Soap adapter: string transformations issues

    I have a difficult issue:
    I want to send a SOAP message to a thirdparty environment ,this environment requieres a special format of the message XML to String; iu2019ll put a sample:
    < SOAP:Body >
    < ns0:application xmlns:ns0=u201Dhttp://xxxxxx/yyyyyyy.com/zzzzu201D >
    < in0>
    < inputMessage >
    < request>name </request >
    < versionMsg>x.0
    u2026u2026u2026u2026..
    < /parameters >
    < /inputMessage>
    This is the meesage that i process with PI. Then when it arrives to the other environment should be as this one, i'll write wrong the chars because the web change it in code...:
    u201C< SOAP:Body >
    < ns0:application xmlns:ns0=u201Dhttp://xxxxxx/yyyyyyy.com/zzzzu201D>
    < in0>
    & lt inputMessage& gt
    & lt request & gt name& lt /request& gt
    & lt versionMsg& gt x.0& lt /versionMsg& gt
    etc etc etcu2026u2026.u201D
    I have changed it in the mapping, it's something easy to map a source structure ot a target whit a string field and mark Return as XML in the source field. that's ok.
    But now is the problem: The SOAP adapter changes all the '&' in differents chars as:&|#|34 (i separate whit |in this sample) or the tag > or < in other ascii chars.
    Some one knows what can i do? i have tried too whit the last post, the module config for SOAP adapter: strictXML2PlainBean but it doesn't work.
    Any help will be appreciated.
    Best regards and thanks in advance.
    Thanks in advance and best regards.

    No, the problem is that the SOAP adapter does the escaping of these chars, so i can't control it. I am trying to deploy a EAR in the server, but i guess that an easiest way should exist for this case.
    The main problem is that the thirdparty system has an filter and this kind of chars are not allowed, this system only understand & lt and & gt in the string field.
    Thanks anyway
    Edited by: Cantabria on Mar 18, 2010 3:07 PM

  • Audition CS6 deleting/trimming issues

    Hi All,
    I'm experimenting with CS6 in an effort to replace Audition 3.0 which crashes all the time lately. I noticed that several features work different and I can't find the way to make them work correctly.
    - In waveform mode, if I trim a recorded audio file (e.g. cut the first few and the last few seconds of silence), CS6 deletes this time frame in the multitrack session also ("pulls" the file left), thus messing up the file's timing totally. Is there a solution to solve this? Audition 3.0 didn't work like this, and it is very annoying, completely makes impossible to fine-trimming the files. I tried to split the file in multitrack mode and then save it, but CS6 ignores this and leaves the file unchanged. I'm stuck with this problem and no matter what I flag or de-flag in the options, it won't go away. I simply want the program to delete the selected part in the editor mode and leave the rest of the file as it was and where it was timewise. Is it possible?
    - Also in waveform mode, if I save a recorded file on a different name, the program doesn't renames and changes the file in the multitrack session. In the file list the name changes, but I have to manually delete the old file and replace it with the new one in the session, which is simply ridiculous (again something that Audition 3.0 did well and CS6 does a stupid, illogical way). is there a chance to make the program do it as it should work?

    All the information you need about gathering the crash information is in the two FAQs I've linked below, and I'd be inclined to do what it says here before running the cleaner tool. The cleaner tool often clears up installation issues, but as the last line of the introduction says, 'It does not affect existing installations of previous versions of Creative Cloud or Creative Suite applications.' Which means that it won't help you with specific crash situations. The information in the FAQs will, though:
    Audition Crashed.  Now what?
    steps to troubleshoot and get past common problems with Audition

  • Bind Variables with AND in String causing Issues in XML & Report Outputs

    Hi all,
    I'm creating a BI Publisher report (10.1.3.2) and am experiencing an issue with the interprutation of Bind Variables in the Data Template.
    Here is an example of some of the Data template
    <dataTemplate name="BudgetDataBU" description="BudgetDataBU" dataSourceRef="DLXN">
       <parameters> 
          <parameter name="p_Year" dataType="Integer" include_in_output="true"/>
          <parameter name="p_Measure" dataType="character" include_in_output="true"/>
          <parameter name="p_Currency" dataType="character" include_in_output="true"/>
          <parameter name="p_Version" dataType="character" include_in_output="true"/>
       </parameters>
       <dataQuery>
          <sqlStatement name="BusUnits">
               <![CDATA[SELECT DISTINCT CC.BUSINESS_UNIT as BUSINESS_UNIT
                        FROM   DLXN_FACT_DATA_DET FD,
                               DLXN.COST_CENTRE CC
                        WHERE FD.COST_CENTRE = CC.COST_CENTRE
                        AND FD.CAL_YEAR    = :p_Year
                        AND FD.Currency      = :p_Currency
                        AND FD.Measure      = :p_Measure
                        AND FD.Version        = :p_Version                                
                        AND CC.DLXN_VIEW = 'Delexian' ]]>
               </sqlStatement>
           <sqlStatement name="Details">
               <![CDATA[SELECT DLXN_FACT_DATA_DET.VERSION,
                               DLXN_FACT_DATA_DET.CURRENCY,
                               DLXN_FACT_DATA_DET.CAL_YEAR as CAL_YEAR,
                               SUM(nvl(DLXN_FACT_DATA_DET.JAN_AMT,0)) as JAN_AMT,
            </sqlStatement>
        </dataQuery>The problem is with the :p_Measure Bind Variable but it could just as easily be any of the other character parameters.
    The particular string value that is causing a problem is "Travel and Expenditure". I believe it is due to the "AND" in the string but this string value cannot be changed in the database to say "Travel & Expenditure".
    I have thought about using a REPLACE function in the SELECT statement but see this as an ugly solution.
    Any input greatly appreciated.
    Kind Regards,
    Gary.

    We remove this restriction ,fix included in BI Publisher July 2009 update for 10.1.3.4.x. The patch number is 8704846.

  • Odd String Truncation Issue

    Hello all,
    I am having the strangest problem with a crystal report truncating a text field when reading records from the DB.  Basically, I have a varchar(6) string field in my Oracle database that holds batch numbers for credit card transactions.  The report worked fine until some users started getting into batches numbered higher than 999.  Anytime a 4th character is added (ie, 1004), my report will read the string as '100'.  All of the other fields in the record are being read fine.
    Oddly enough, this only happens on some databases/machines and not others.  For instance, a DB dump of this data to a local machine will work fine and the report reads '1004'.  I have captured the SQL the report is using to obtain records and pasted it in an Oracle client (TOAD) and the record pulls fine with the batch number being '1004'.  The width of the field on the report is long enough to display much more than 4 characters, so that's not the issue.  Anyone seen this type of issue before or have any ideas on how to troubleshoot it?
    We are using Crystal Reports XI R2 to design the report.

    Hi Chuck Reed,
    Can you add that field through Add Command and see all digets are coming in ?
    Go in Datbase expert --Under you datbase connection click on Add Command and write sql like
    Select BatchNumber from Table and link the batchnumber with your table batch number and place command batchnumber in report and check.
    Thanks,
    Sastry

  • String Trim

    Hello,
    I'm new to Java programming, I have programmed in other languages. Heres my problem:
    At the console someone enters say... "monkee1;monkee2;monkee3 -a -b -c"
    how can i trim it to just "monkee1;monkee2;monkee3 -a -b -c" getting rid the white space
    Thanks in advance

    My solution asumed that 1 space must be kept.You are probably right, so, my version needs to be upgraded to[...]
    String tmp;
    String del; // new
      else if ( ";".equals(tmp) ) {
        // arg delimiter -> reset
        helper.append(tmp);
        result.add(helper.toString());
        helper.delete(0, helper.length());
        del = ""; // new
      else {
        // arg text
        helper.append(del); // new
        helper.append(tmp);
        del = " "; // new

  • String.trim() problem.

    Hi
    I have an ascii file that I parse, the first like is
    " hello there "
    When I do a trim() on the String. It returns:
    " hello there "
    If I do:
    Character.isSpaceChar(str.charAt(0))
    It returns true.
    If I go into into the file using a text editor and delete the spaces and replace them, the trim() work.
    It seems that the characters are not white spaces, although isSpaceChar returns true.
    Any ideas?
    Thanks
    George

    You might use regex and the space categories "\\p{IsZs}" or "\\p{Zs"}
    [url http://www.fileformat.info/info/unicode/category/Zs/list.htm]http://www.fileformat.info/info/unicode/category/Zs/list.htm
    [url http://unicode.org/Public/UNIDATA/UCD.html#General_Category_Values]http://unicode.org/Public/UNIDATA/UCD.html#General_Category_Values
    [url http://www.fileformat.info/info/unicode/category/index.htm]http://www.fileformat.info/info/unicode/category/index.htm
    Sun's Regular Expression Tutorial for Java
    Regular-Expressions.info
    str = str.replaceAll("^[\\s\\p{Zs}\\p{Zl}\\p{Zp}]*\\b(.*)\\b[\\s\\p{Zs}\\p{Zl}\\p{Zp}]*", "$1");seems like it might work, but it might also be overkill.

  • A question about string.trim()

    I got a fragment of code as follows:
    String s = "abcd ";
    boolean a = (s.trim()=="abcd");
    boolean b = (s =="abcd ");
    Why a is false, b is true?

    The reason why the below code has true assigned to be is quite easy to explain:
    String s = "abcd";
    String y = "abcd";
    boolean b = (s == y);
    ...The String class has a "Pool" of strings. When you use String literals; the compiler automatically checks if it is in the String pool already and if it exists; a reference to that String is returned; if not a new entry in the pool is added and then you get a reference to that. This is only true for Stirng literals and String created using the intern() method.
    If you compile this code you will see that the strings are not equal:
    public static void main(String args[])
      String s = "abcd";
      String y = args[0];
      boolean b = (s == y);
      System.out.println(b);
    }This is because the "abcd" is in the String pool when your program starts; but because the value "abcd" passed in (is not created in the pool automaticlaly). Therefor they are two different String objects.
    This code block shows that you can add Strings to the pool. The intern() method checks to see if the String is in the pool already and if it is it will return you a reference to it; if not it will create one and then return it.
    public static void main(String args[])
      String s = "abcd ";
      String y = args[0].intern();
      boolean b = (s == y);
      System.out.println(b);
    }- Chris

  • IP to string node issue

    Hi,
       In our application we are exchanging data on every 50 ms between client and server systems via UDP.  The data exchange between client and server was happening without any issue except the memory leak. Later we found that the IP to String function with dot notation input as false on the UDP listener creates the memory leak. So we changed the IP to String function with dot notation input as true then the memory leak issue was gone.
    Is anybody experienced such memory leak issue with the IP to String Function and how managed this issue? what would be the reason for the memory leak with the IP to String function with dot notation input as false? 
    Thanks
    Sathiyanarayanan

    If dot notation is false, the function needs to query a DNS server, something I would probably not do every 50ms. Querying a DNS server can be slow, so maybe you get a built-up of DNS lookup requests. Can you open a command window and do a "netstat -n" during run. how many connections are listed?
    What is the purpose of your use of the IP-to-string function. How often does the IP change? Is it the same most of the time?
    What is your LabVIEW version? What is your OS? Can you show us some code on how you are using this?
    The Devil wrote:
    I have myself not faced such a problem but I have used the inplace structure for memory management. ...
    This problem cannot be solved with the in-place structure. Your answer is completely meaningless in this context. Can you explain your thought process that led you to suggest this as a solution? Makes no sense to me!
    Message Edited by altenbach on 01-24-2010 09:57 PM
    LabVIEW Champion . Do more with less code and in less time .

  • String trim() does not work

    Here is the code:
    String item = " abc ";
    int before = item.length();
    item.trim();
    int after = item.length();
    The result is before == after.
    What's wrong?

    Remember that Strings in Java are immutable, so calling item.trim() does nothing to the original String. Did you notice that the trim() method returns a String? The String that is returned is the new String that has been trimmed. So, you must assign this new value to the item variable.
    item = item.trim();
    SAF

  • String Concatenation issue

    Hi all,
    I have a simple query which concatenates three columns together, separated by a comma. Something like...
    SELECT FK_COMMUNITY||', '||FK_BUILDING_ID ||', '|| FK_ROOM_TYPE AS preference
    FROM preferences;
    The issue is that not all these columns are populated, in some cases they all have data and in some cases the data is missing (NULL).
    The problem is the output leaves the formatting off example:
    PREFERENCE
    Avery Hill, ,
    , TUD,
    , DEV,
    , DEV,
    , CUT,
    , CUT,
    , BIN, BINSTA
    , MMA, MMASTE
    , BIN,
    , MMS, MMSSTU
    Any help would be appreciated. Many thanks

    So in general you need to:I'd prefer to use XMLCAST (where it is supported) - or maybe sometimes EXTRACTVALUE :
    SQL> set define off
    SQL> with prefences as (
    select 0 as row_id, 'Avery & Hill' as fk_community, null as fk_building_id , null as fk_room_type from dual
    union select 1, null, 'TUD', null from dual
    union select 2, null, 'DEV', null from dual
    union select 3, null, 'DEV', null from dual
    union select 4, null, 'CUT', null from dual
    union select 5, null, 'CUT', null from dual
    union select 6, null, 'BIN', 'BINSTA' from dual
    union select 7, null, '<MMA>', 'MMASTE' from dual
    union select 8, null, 'BIN', null from dual
    union select 9, null, 'MMS', 'MMSSTU' from dual
    select xmlcast(xmlquery('string-join(./*,",")' passing xmlforest(fk_community, fk_building_id, fk_room_type) returning content) as varchar2(100)) str
    from prefences
    STR                                                                            
    Avery & Hill                                                                   
    TUD                                                                            
    DEV                                                                            
    DEV                                                                            
    CUT                                                                            
    CUT                                                                            
    BIN,BINSTA                                                                     
    <MMA>,MMASTE                                                                   
    BIN                                                                            
    MMS,MMSSTU                                                                     
    10 rows selected.

  • String comparision issue

    Good morning folks,
    I want to take basically month and year of sysdate and compare with month and year of field in database and compare them.
    But it is not working.
    select case when
    (concat(TO_CHAR(sysdate, 'MM'), to_char(sysdate,'YYYY')) >
    concat(to_char(max(as_of_date),'MM'), to_char(max(as_of_date),'YYYY'))) then 'Not Archived'
    else 'Archived' end from historical_advs_curr_eom
    can someone suggest me any other better way of doing?
    May be I shouldn't convert sysdate to string?
    Thanks much folks.
    regards
    nathan

    user12131044 wrote:
    May be I shouldn't convert sysdate to string?Exactly. A string is not a date. Nor a number. So comparisons using strings do not behave like comparisons using dates and numbers.
    Always try and use data in its native format - do not convert it into another data type as that data type will often behave differently and not provide the expected answer.
    It is also not a good idea from a performance perspective. If you have an index or a number columns, the index value is numeric. If you now do a conversion of the column to a string and compare using that, it renders that index that contains numbers and not strings, useless.
    Conversion also is an overhead - especially when it needs to be applied to every single row that the SELECT statement hints.
    So rather stick to the native data type of that column. It is a lot more sensible.

  • Strange String literal issue - Newbie alert !!

    Hello all,
    Please forgive if this is dumb but I have a deadline to meet.
    I have a function func_name(int num, String ip_s1, String ip_s2)
    It works just fine if I do
    somaclass.func_name(123,"string1","string2");
    but not for someclass.func_name(123,string_var,string_var2);
    even though the function "receives" the input correctly.
    I have no clue as to what to do. Please help !

    You have a bug in your code. My guess is that when you're testing with "string1", "string2", your code can cope with those values, but when you pass the values of String variables, your code can't cope with the values in question.
    It's hard to say exactly what the problem is, however, since you give so little detail. It's not clear what's happening that's wrong, other than not working fine.
    The best thing you can do is add some debugging code. See if you can spot a pattern with the values of the variables.
    My general guess is that one or both of the variables in question are null, and you're dereferencing the string arguments. And if it's not that, then my guess is that one or both is zero-length, and your code assumes non-zero length. And if it's not that, then my guess is that you're searching the strings for certain substrings, and the substrings are not present, and your code assumes the presence of the substrings.

Maybe you are looking for