1 18 19 package com.Ostermiller.util; 20 21 import java.io.UnsupportedEncodingException ; 22 import java.net.URLEncoder ; 23 24 33 public class NameValuePair { 34 35 38 private String name; 39 40 43 private String value; 44 45 53 public NameValuePair (String name, String value){ 54 if (name == null) name = ""; 55 if (value == null) value = ""; 56 this.name = name; 57 this.value = value; 58 } 59 60 67 public String getName(){ 68 return name; 69 } 70 71 78 public String getValue(){ 79 return value; 80 } 81 82 89 public String toString(){ 90 try { 91 return toString("UTF-8"); 92 } catch (UnsupportedEncodingException uex){ 93 throw new RuntimeException (uex); 95 } 96 } 97 98 106 public String toString(String charset) throws UnsupportedEncodingException { 107 return URLEncoder.encode(name, charset) + "=" + URLEncoder.encode(value, charset); 108 } 109 } 110 | Popular Tags |