Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to add code in my jsp file.  RSS feed

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add code in my jsp(java coding or c) file. But all the formatting is gone + it becomes very hard to use < & gt. Is there any way so that we can directly copy paste the code and that too retaining their format.

Thanks in Advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying that you want to display source code in the user's browser?
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YES.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Himanshu said:
I want to add code in my jsp(java coding or c) file. But all the formatting is gone + it becomes very hard to use < & gt. Is there any way so that we can directly copy paste the code and that too retaining their format.


Hi Himanshu,
I can think of something like this, maybe you can write a
tag, the body of the tag will contain code you need to display.
In the tag implementation get the body(the source code to display) and use the apache common lang's StringEscapeUtils

http://commons.apache.org/lang/api-release/org/apache/commons/lang/StringEscapeUtils.html

Or

jTidy's HTMLEncode

http://jtidy.sourceforge.net/multiproject/jtidyservlet/apidocs/org/w3c/tidy/servlet/util/HTMLEncode.html

To encode your text and display.
[ November 16, 2008: Message edited by: Amol Nayak ]
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amol. Will get back to you after trying it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<cut> will automatically HTML-encode its output.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. That seems to be an easier solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!