File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes jsp:include corrupts characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:include corrupts characters" Watch "jsp:include corrupts characters" New topic
Author

jsp:include corrupts characters

Kelly Dolan
Ranch Hand

Joined: Jan 08, 2002
Posts: 109
i have the following...

// HTML page
<html>
<head>
<script type="text/javascript" src="scripts.jsp"></script>
...

// scripts.jsp
<%@page contentType="text/javascript" %>
<jsp:include page="page1.js" />
...

// page1.js
var obj = new Array();
obj[obj.length] = "str1";
obj[obj.length] = "str2";
obj[obj.length] = "str &PlusMinus ing";


we noticed a problem when the HTML displayed the "±" value found in obj[] - it was some weird funky character, obviously corrupt. if I inspect page1.js, the "&PlusMinus" is the correct character. if I inspect scripts.jsp after the jsp:include and before it is sent to the browser, the "±" is corrupted. therefore, i can only come to the conclusion that the jsp:include is corrupting the character.

a) this is a problem for more than just ±
b) jsp:include doesn't seem to have a parameter or attribute that can be set re: charset
c) JSP documentation states that adding "charset:UTF-8" to the @page declaration has no affect on jsp:include
d) I cannot use the other "include" because our content is dynamic, not static
e) I cannot reference page1.js from the HTML directly because some of our pages are not actually in web-accessible locations

help! how does one get jsp:include to use the correct charset so not to corrupt the characters of the content being included?

thanks!
kelly
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
Can you please define what "corrupted" means?
How did you determine it was corrupted?

If you try and load scripts.jsp directly, does it load the content you are after? (including in the view source?)

What would you expect the &plusMinus to do in a javascript string in any case?

Kelly Dolan
Ranch Hand

Joined: Jan 08, 2002
Posts: 109
>> Can you please define what "corrupted" means? How did you determine it was corrupted?

Sure. And my mistake I left an important piece of info out... The ± is in an XML file that gets passed thru a Transformer (XSL) that generates page1.js. When it is in page1.js, it is no longer ± but C2B1. This was determined by opening page1.js in a HEX editor.

Following this, we used a debugger to see the result of scripts.jsp on the server before it is returned as the HTTP response. The character is no longer C2B1.

>> If you try and load scripts.jsp directly, does it load the content you are after? (including in the view source?)

If you mean enter the URL to scripts.jsp directly in the browser, the result is the same. Yes, we get the full content we expect but the character is corrupt.

>> What would you expect the &plusMinus to do in a javascript string in any case?

Technically nothing. But the javascript creates HTML at run-time given these values and places this value in let's say a <div> tag. Instead of seeing a true plus/minus sign, we see garbled characters (e.g., A, boxes).
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
My HTML reference says you want amp plusmn ; to get ± (without spaces of course)
which has the decimal value 177 get the plus/minus character.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:include corrupts characters