Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 10:42 PM   PM User | #1
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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!
zenithwolf is offline   Reply With Quote
Old 09-06-2007, 11:07 AM   PM User | #2
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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/>
ess is offline   Reply With Quote
Old 09-06-2007, 08:37 PM   PM User | #3
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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!
zenithwolf is offline   Reply With Quote
Old 09-06-2007, 08:59 PM   PM User | #4
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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.
ess is offline   Reply With Quote
Old 09-06-2007, 11:14 PM   PM User | #5
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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);
}
zenithwolf is offline   Reply With Quote
Old 09-06-2007, 11:17 PM   PM User | #6
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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
zenithwolf is offline   Reply With Quote
Old 09-07-2007, 11:17 AM   PM User | #7
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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
ess is offline   Reply With Quote
Old 09-07-2007, 04:38 PM   PM User | #8
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
nope still gives me all that space :/
zenithwolf is offline   Reply With Quote
Old 09-07-2007, 08:09 PM   PM User | #9
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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!
zenithwolf is offline   Reply With Quote
Old 09-07-2007, 08:37 PM   PM User | #10
zenithwolf
New Coder

 
Join Date: Aug 2007
Posts: 33
Thanks: 7
Thanked 0 Times in 0 Posts
zenithwolf is an unknown quantity at this point
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 ><
zenithwolf is offline   Reply With Quote
Old 09-07-2007, 09:45 PM   PM User | #11
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
hahha...cannot believe that was causing the problem...but glad that you have found a solution.

ess is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:24 AM.


Advertisement
Log in to turn off these ads.