I hope someone has the answer to this one ...

By far the most cumbersome task (not technically challenging, just
*lots* of work) I've encountered in servlet programming is converting
the data in http requests into java objects.  GetParameter() is
basically a pain, but it's probably the best we can hope for in the html
world (slightly improved methods for converting the resulting string to
different datatypes included below for anyone who's interested).

The XML world, however, seems to offer the promise of better.  If the
incoming request contains tags which tell me what the information its
sending me is supposed to be, I should be able to stick those into
properties on objects directly (more or less).  Should make the process
*much* easier, no?

Pardon if I've been out of the loop on this one, but has anyone seen or
done anything in this direction?
Any responses would be much appreciated.

btw - I was just at MS DevDays yesterday (it's always good to keep
abreast of what your opponents are up to), there's a new call in ASP to
do effectively this in the COM world - converts incoming XML into ADO
stream directly - works very nice.  If we servlet folks don't have a
corresponding story rsn, I feel a real tail-kicking coming on here, ...

// get parameter methods for other basic datatypes
protected boolean getBooleanParameter (HttpServletRequest rq, String
paramName)
 {
  String str = rq.getParameter(paramName);
  if (str.equals("") || str == null) return false;
  else return (str.equals("true") || str.equals("TRUE")); // can also
use Boolean class here
 }

 protected double getDoubleParameter (HttpServletRequest rq, String
paramName)
 {
  String str = rq.getParameter(paramName);
  if (str.equals("") || str == null) return (double) 0.0;
  else return (new Double(str)).doubleValue();
 }

 protected float getFloatParameter (HttpServletRequest rq, String
paramName)
 {
  String str = rq.getParameter(paramName);
  if (str.equals("") || str == null) return (float) 0.0;
  else return (new Float(str)).floatValue();
 }

 protected int getIntegerParameter (HttpServletRequest rq, String
paramName)
 {
  String str = rq.getParameter(paramName);
  if (str.equals("") || str == null) return (int) 0;
  else return (new Integer(str)).intValue();
 }

 protected long getLongParameter (HttpServletRequest rq, String
paramName)
 {
  String str = rq.getParameter(paramName);
  if (str.equals("") || str == null) return (long) 0;
  else return (new Long(str)).longValue();
 }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to