This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How to escape % in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How to escape % in JSP" Watch "How to escape % in JSP" New topic
Author

How to escape % in JSP

Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
Hi All,
If in a jsp file, I just want to display the following line:
This is a test of display <%.
in JSP, I wrote, This is a test of display <\%, I used the escape, why it still shows Server Error?

Thanks a lot.

Hai
Sumitro Palit
Ranch Hand

Joined: Dec 13, 2003
Posts: 37


This worked for me.
(IE 6, Tomcat 4.1.03 )

- ortimuS
Balamurugan Muthiah
Greenhorn

Joined: Mar 14, 2002
Posts: 17
Hai Lin

Ortimus is correct. That works for me too. Can you post the code which you used and also the error you get? That would help us understand your problem better.


Regards<br />Bala<br />SCJP 1.2, SCWCD 1.4
kishore batchu
Greenhorn

Joined: May 29, 2004
Posts: 2
Hai Lin,

Just now registered in java ranch.

i seen your code.

I got one solution for your problem.

my solutions for your problem

in Example.jsp
---------------

<html>
<body bgcolor="cyan">
<h1>
This is a test of display <%
</h1>
</body>
</html>

when we deploy this jsp in web server we get output like this

This is a test of display <%

Here < is entity ref to < symbol
% is entity ref to % symbol

Thanks
kishore
kishore batchu
Greenhorn

Joined: May 29, 2004
Posts: 2
Hi Lin,

my solution to your problem is

in exmple.jsp


<html>
<!--
<body bgcolor="cyan">
<h1>
This is a kishore test of display <%
</h1>
</body>

-->
<!--
here < is a entity refer to <
% is a entity refer to %

-->
</html>

Thank you
kishore batchu
Hai Lin
Ranch Hand

Joined: May 23, 2004
Posts: 79
ortimus,
Thanks a lot. You are right, just using <\% should works, I tested on the Tomcat 5, working fine. The problem I met is the webserver of iplanet6.0, I will test on iplanet6.0 laster.
But another question, how to you display
<%@ include file="test1.jsp" %> to the screen as it is? I mean, how to escape <%@ sign in the jsp? I used <%\@ ... to test, not working.
Waiting for you guys's reply!

Thanks a lot!

Hai
Atanas Roussev
Ranch Hand

Joined: Apr 07, 2004
Posts: 33
<%\@ include file="test1.jsp" %>
Atanas Roussev
Ranch Hand

Joined: Apr 07, 2004
Posts: 33
Sorry Hai Lin

Even though i wanted to write it properly today i saw i gave you wrong syntax.

Proper is:

<\%@ include file="lepage.jsp" %>
[ May 31, 2004: Message edited by: atanas roussev ]
Sumitro Palit
Ranch Hand

Joined: Dec 13, 2003
Posts: 37
Hai,

I have not used iPlanet - but you might try using html escape characters inplace of <, > and see if that helps - even though thats typically a client browser issue.

Also, take a look at the html source generated by each server (Tomcat vs iPlanet) via the browser's View - Source and see if there is any difference that is causing this behavior.

Hope this helps,

- ortimuS
[ June 01, 2004: Message edited by: ortimus tilap ]
Emman lopez
Ranch Hand

Joined: Mar 11, 2004
Posts: 38
Hi hai lin,
I think ortimus is right , you could use the following;


hope this helps example helps you.


E.L.<br /> <br />SCJP
Emman lopez
Ranch Hand

Joined: Mar 11, 2004
Posts: 38
sorry, it actual show the < symbol
what I meant was
< %@ include file="test1.jsp" %>

with the ; after the lt.
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
You really should escape the '<' in your HTML text. Once you do that, it's easy


[ June 08, 2004: Message edited by: Michael Zalewski ]
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
It's hard to make this board display what I intended.

But '<' should never be in your web page. It should be '&lt;'. Once you do that, it's easy to make the page say <%, which you code as

 
 
subject: How to escape % in JSP
 
Similar Threads
Links in properties file
Need Help outputting double quotes
escape character in jsp page
Any "escape character" in HTML?
textarea - Dash