File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to display string with special characters

 
riya das
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20171
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20171
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 859
Chrome IBM DB2 Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
var Temp= '<%= TweetText%>';

WP
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the quotes in the JSP


and drink it all up
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
riya das
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic