Tricky Tricks ›› Programming Tricks ›› Java Tricks ›› Reading Non Plain Ascii From Html Forms Into Java Servlet Applications

Reading Non Plain Ascii From Html Forms Into Java Servlet Applications

Java Programming Tricks

Reading non plain ASCII from HTML forms into Java Servlet Applications:

When you want to read extended values (e.g. ISO-8859-1) from a HTML Form into a Java Servlet, make sure you set the correct Characterset, before reading the values, or you will get only 7-Bit characters.

 // Get HTML-Form Parameters
 
 import java.util.*;
 import oracle.html.*;
 import oracle.owas.wrb.services.http.HTTP;
 
 public class GetFormParm {
 
   protected HTTP http = null;
 
   // Constructor
   public GetFormParm() {
     this.http = HTTP.getRequest();
   }
 
   // Get URL Parameter for strKey
   public static String getURLParm(HTTP http, String strKey) {
     String strValue;
 
     // Set URL character set (default ISO-8859-1)
     http.setURLCharacterSet("ISO-8859-1");
     strValue = http.getURLParameter(strKey);
     if (strValue == null) { strValue = ""; }
     if (strValue.compareTo("") == 0) { strValue = ""; }
 
     return strValue;
   }
 }
 

Partners