to add on

In hope this will help u...

An approach towards handling the special characters has been mentioned
below.
Steps to be followed for Special Character Handling
Gist of the approach followed
        [A] Forward Flow - While Adding data
        - Use escape function to encrypt the field data before submission of
the form to the servlet
        - On getting the values from the HTTP Request object, apply the
java.net.URLDecoder.decode method to get the actual content
        [B] Backward Flow - While Retrieving data
        - After retrieving data, check if there are spaces and convert the
spaces to some escape sequence ('SpAcE' in this case)
        - On the output of the above step invoke the
java.net.URLEncoder.encode method to encrypt the data
        - On load of the screen, use the unescape function to decrypt the
field data and replace the escape sequence for spaces ('SpAcE') with ' '.
[A] Forward Flow - While Adding data
1. Just before submitting the form to the servlet, call the escapeFields
method, the parameter (singular) to be passed are the field names (only the
fields that allow special characters) seperated by comma.
E.g. Inside OnClick fn of [Add/Save] button

function fnOnClickOfAdd() {
...
...
...
escapeFields('fieldName1,fieldName2,fieldName3,fieldName4,fieldName5');
fnToInvokeServlet();
}

2.and then use decodeString method to decode.
[B] Backward Flow - While Retrieving data
1. While extracting the data use encode method

2. OnLoad of the screen call the unescapeFields function to decode the field
data

JavaScript Source
-----------------

// Function Name : escapeFields
// Description : All spaces, punctuation, accented characters, and any
// other non-ASCII characters are replaced with %xx
// encoding, where xx is equivalent to the hexadecimal
// number representing the character.
// Parameters
function escapeFields(msFields) {
var maFieldsArray = msFields.split(",");
var miIcnt;
for (miIcnt=0; miIcnt < maFieldsArray.length; miIcnt++) {
field_ =
top.getFrameReference('CAFE_form').document.getElementById(maFieldsArray[miI
cnt]);
if (field_ != null) {
field_.value = escape(field_.value);
}
}
}
// Function Name : unescapeFields
// Description : All characters encoded with the %xx hexadecimal form are
// replaced by their ASCII character set equivalents.
function unescapeFields(msFields) {
var maFieldsArray = msFields.split(",");
var miIcnt;
for (miIcnt=0; miIcnt < maFieldsArray.length; miIcnt++) {
field_ =
top.getFrameReference('CAFE_form').document.getElementById(maFieldsArray[miI
cnt]);
if (field_ != null) {
fieldContent_ = field_.value;
fieldContent_ = unescape(fieldContent_);
field_.value = fieldContent_.replace('SpAcE',' ');
}
}
}
Java Source
------------
public class ApplicationUtilityClass {
...
...
...

/**
* Encodes the embeded spaces into a literal.
*
*/
public static String encodeSpaces(String unformattedString) {
String formattedString = null;
if (unformattedString != null) {
formattedString = "";
for (int i=0; i<unformattedString.length(); i++) {
switch (unformattedString.charAt(i)) {
case ' ':
formattedString += "SpAcE";
break;
default:
formattedString += unformattedString.charAt(i);
}
}
}
return formattedString;
}
/**
* Encodes the String into appropriate ASCII value.
*
*/
public static String encodeString(String normalString) {
String methodName = "encodeString";

if (normalString != null) {
normalString = encodeSpaces(normalString);
String encodedString = java.net.URLEncoder.encode(normalString);
return encodedString;
}

return null;
}
public static String decodeString(String encodedString) throws
com.aig.cafe.framework.util.ActionException {
String methodName = "decodeString";
try {

if (encodedString != null) {
String decodedString = java.net.URLDecoder.decode(encodedString);
return decodedString;
}

} catch (java.lang.Exception e) {
throw new com.aig.cafe.framework.util.ActionException(e);
}
return null;
}

...
...
...
}


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Vikramjit Singh
Sent: Tuesday, February 04, 2003 4:11 PM
To: [EMAIL PROTECTED]
Subject: Re: JSP to JavaScript error


when you encode it you must decode it also, to get the value. try using the
decode function.


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Jan Arenö
Sent: Tuesday, February 04, 2003 1:53 PM
To: [EMAIL PROTECTED]
Subject: JSP to JavaScript error


Hi, this is a JSP/Javascript question

I send a Oracle db Rowid between two pages. Since the Rowid can contain '+'
char i use URLEncoder.encode.

I have a link
<a href="javascript: nextPage('<%=URLEncoder.encode(Rowid)%>')">Next
page</a>

<script>
function nextPage(rowid)
{
  //Do some stuff... and end in:
  eval("document.location='step3.jsp?searchrow="+rowid+"'");
}
</script>

The URLEncoder fix the '+' char to %2 (i think it is), and that works fine.
But sins the javascript call will be
<a href="javascript: nextPage('12345%267890')">Next page</a>
the browser sends '12345+67890' to the function, and there the '+' sign will
be converted to an ' ' (space) in the url.
How do I fix this? Is there a smart way?

OBSERVE!!!
I have a IE specific solution also, where I put the javascript part in a
OnClick
<TD onClick="nextPage('<%=URLEncoder.encode(Rowid)%>')">Click this td to go
to next page</TD>

But this does not Work on NS etc!!!

Also observe that NS can handle the + sign parameter to the javascript


Regards Jan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

 http://java.sun.com/products/jsp
 http://archives.java.sun.com/jsp-interest.html
 http://forums.java.sun.com
 http://www.jspinsider.com

Reply via email to