Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: white spaces

  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts

    white spaces

    In my jsp I am getting data from a server and then sending it to an AJAXified html page where the data is read, now I'm not sure whether to put this in the AJAX forum or here, but one particular output I send from the jsp, the output has like 200 white spaces before the output, and no matter what i do, split, trim it it doesnt go away! help!

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    Although it seems like white space to you and I....there are characters such as \n \r etc that would not be visible once rendered on a page.

    try and remove these characters before outputting any data using regular expressions.

    Note: Sometime these characters are replaced with <br/>

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    agreed. But all I am doing is getting data from the server in my jsp function, and when i print it in the jsp function, it doesnt show any crazy spaces, and still trim it just to be sure, still no use, when the thing returns in AJAX, I get the huge space... and Im sure its not carriage returns or something like that its just big blank space!

  • #4
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    do you mind posting the output...so we know what we are looking at here..instead of making assumptions as to what might be the cause of the problem etc.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    this is the white space im talking about.



    and this is the simple code that goes with it

    Code:
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    	  // store processed response text
          var getVal = xmlHttp.responseText;
    	  // display the value to user
    	  default_servs = getVal;
    	  alert("var getVal = xmlHttp.responseText = " + getVal);
    }

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    oh btw that code is in my .js ajax file, but the response comes from this function in my jsp:

    Code:
    public String calculateServ(recipe.ProcessIngredients ing, String query) {
    ing.processRequest(query);
    String outString = ing.getServings(query);
    return outString;
    }
    the processRequest and getServings methods lie in my bean class files and are all ok and the getServings method returns String...will check that but I fail to see anything that might generate random blank spaces

  • #7
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    do you mind trying out this js function.
    Code:
    function clean(val) {
    	return val.replace(/^\n{2,}/g, '').replace(/\n{2,}$/g, '').replace(/\n{2,}/g, '\n');
    }
    here is how you can call it using your script
    Code:
    if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
    	  // store processed response text
          var getVal = xmlHttp.responseText;
    	  // display the value to user
    	  default_servs = getVal;
    	  alert("var getVal = xmlHttp.responseText = " + clean(getVal));
    }
    let's know if that worked or not.

    cheers,
    Ess

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    nope still gives me all that space :/

  • #9
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    damn this thing is pissing me off, because (i think) of these spaces my responseXML cannot detect any of the HTML content in the response String!!

    NEED HELP FAST!

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    33
    Thanks
    7
    Thanked 0 Times in 0 Posts
    SOLUTION FOUND!

    stupidest problem I have ever encountered...turns out the code after %> statements counted as an out.println();!!!!!!!!

    i had to write my code this crazy way now:

    Code:
    <%@ page import="java.util.*"%><%@ 
    page import="recipe.*"%><%@
    bah congrats to jsps ><

  • #11
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    hahha...cannot believe that was causing the problem...but glad that you have found a solution.



  •  

    Posting Permissions

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