Here\'s something to get over the fact that some web browsers don\'t like to play nice when passing parameters through forms. The problem is, sometimes when you want to pass a form variable which happens to be an empty string, some browsers will pass it just fine (as "") and others will just exclude it completely. A little consistency would be nice.
Use this in your jsp\'s or servlets to hold your request parameters in.
You can use the code below, or you can use the constantly updated version in my aurora.servlet package- Params.java
public class Params
{
private Hashtable params = new Hashtable();
/**
* take all of the parameters from the request and filter out the
* ones with blank values.
*/
public Params (HttpServletRequest request) {
Enumeration enum = request.getParameterNames();
while (enum.hasMoreElements()) {
String name = (String) enum.nextElement();
String values = request.getParameter(name);
if (values != null) {
if (!"".equals(values.trim()))
setP (name, values);
}
}
}
/**
* Set a parameter
*/
public void setP(String parameter, String value) {
params.put(parameter, value);
}
/**
* remove a parameter
*/
public void removeP(String parameter) {
params.remove(parameter);
}
/**
* get a parameter, returns null if it isn\'t there.
*/
public String getP(String parameter) {
return (String)params.get(parameter);
}
/**
* return a parameter, or return the default_value passed if it
* is not present.
*/
public String getPtd(String parameter, String default_value) {
String s = (String)params.get(parameter);
return s == null ? default_value : s.trim();
}
}