This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Unable to display string with special characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to display string with special characters" Watch "Unable to display string with special characters" New topic
Author

Unable to display string with special characters

riya das
Greenhorn

Joined: Sep 16, 2011
Posts: 9
Hi All,

I am working on a code where I need to fetch tweets using an API and display on a google map. I am using JSPs and Servlets.
Everything is working fine, except for one part :

I am not able to display the content of the tweets that I am fetching. Following is the code for same -

<% String TweetText= tweet.getText(); %> => This is working fine as TweetText is getting the content (Most of the times the tweets have special characters)

But when I use the following code, the code breaks and I am not able to understand what is going wrong.
var Temp= <%= TweetText%>;
I used various functions like encodeURI() function, stringconversion functions, but nothing seems to work. It is also not working for tweets with no special chars.

I am new to JSP, so I am not sure if there is something very basic that I am missing out here.

Any help would be highly appreciated!

Thanks!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Would it be fair to guess that

is supposed to be generating a line of JavaScript code?

If that's the case, then just take a moment to have a look at the generated code. It probably looks like this:

Which as you can see isn't valid JavaScript.

Or if I guessed wrong, then could you spend a moment to explain the problem? Maybe some of our FAQ pages would help: ItDoesntWorkIsUseless, TellTheDetails, for example.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Also, you started out by saying that your problem was with tweets with "special characters" -- although you didn't say what those characters were. But then you also said
It is also not working for tweets with no special chars.

So wouldn't that mean that it doesn't work for any tweet at all? In which case there would be no point in trying to figure out how to deal with those mysterious special characters.
riya das
Greenhorn

Joined: Sep 16, 2011
Posts: 9
Paul, you are right. The output is seen as :



I think that is where the problem is. How do i fix it to get double quotes?
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

var Temp= '<%= TweetText%>';

WP
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2339
    
  28

Put the quotes in the JSP


and drink it all up
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61090
    
  66

It's clear at this point that you don't know how basic JSP technology works. Please read this article to learn what JSP is and why you had this issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
riya das
Greenhorn

Joined: Sep 16, 2011
Posts: 9
Thank you guys ! Now that I look back, it really was silly and I was struggling for so long - I sure need to have a look at the primer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to display string with special characters