Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 htmlentities, java+jsp+javascript

views
     
TSgiasens
post Oct 27 2006, 02:18 PM, updated 20y ago

On my way
****
Senior Member
625 posts

Joined: Jan 2003


in my jsp page, i hav the following javascript code
where it will set the form txtfield value

function fnRandom(var1) {
document.frm.txt1.value = var1;
}



in my java code,
i retrieve record from db which contain htmlentities.
then i suppose to printout to html like this

out.print("<a href=\"javascript:fnRandom("DB_INPUT_STR");\">runJS</a>");
-----
my problem is
when my DB_INPUT_STR contain single quote/double quote or other htmlentities, it will break my javascript.

anyidea?

rukawa
post Oct 27 2006, 03:46 PM

::+::KukuKawa::+::
******
Senior Member
1,903 posts

Joined: Jan 2003
From: Wg Maju


From the java code itself, I think you have to either filter it out if those entities doesn't affect anything
TSgiasens
post Oct 27 2006, 03:54 PM

On my way
****
Senior Member
625 posts

Joined: Jan 2003


yeah filter out. but hav to get it back when the value goes into the textfield. else it looks weird.

look my code, the error occur when i insert the double quote.
and if double quote not exist, it runs fine.
i manage to escape the single code but not double quote.

CODE

<html>
<head>
</head>
<body>
<form name="frm">
<input name="txt1" type="text" value=""><br />
<input type="button" value="print"
onclick="javascript:fnFn('\(\@#$^\)*!&df"\'\<;:?\>')"  <------ this line
/>
</form>

<script>
function fnFn(inputVal) {
document.frm.txt1.value=inputVal;
}
</script>
</body>
</html>


This post has been edited by giasens: Oct 27 2006, 03:57 PM
rukawa
post Oct 27 2006, 04:12 PM

::+::KukuKawa::+::
******
Senior Member
1,903 posts

Joined: Jan 2003
From: Wg Maju


This was the same question i posted up last time in here. My only way is to try to avoid any double quotes in that area.
TSgiasens
post Oct 27 2006, 04:21 PM

On my way
****
Senior Member
625 posts

Joined: Jan 2003


uhm. that's user input.
ok. i use escape & unescape,
it works in my jsp page,
but not in normal html such as this =.=;

CODE

<html>
<head>
</head>
<body>
<script>
function fnFn(inputVal) {
document.frm.txt1.value=unescape(inputVal);
}

var str = '\(\"\'\<;?\>';
//document.write(escape("\(\"\'\<;?\>"));

</script>
<a href="javascript:alert(str)">prompt</a>
</body>

<form name="frm">
<input name="txt1" type="text" value=""><br />
<input type="button" value="print" onclick="javascript:fnFn(escape('\(\'\<;?\>'));" />
</form>

</body>
</html>


This post has been edited by giasens: Oct 27 2006, 05:18 PM

 

Change to:
| Lo-Fi Version
0.0130sec    0.52    5 queries    GZIP Disabled
Time is now: 5th December 2025 - 12:36 AM