|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.mortbay.Servlets.ServletDispatch
Class to aid in servlet method dispatching and argument parsing
public void doGet(HttpServletRequest req, HttpServletResponse res) { ServletDispatch disp = new ServletDispatch(req, res); if (!disp.dispatch(this, null)){ // handle error... } } public boolean Add(ServletDispatch disp, HttpServletRequest req, HttpServletResponse res) { int foo[] = null; foo = (int[])ServletDispatch.parseArg(foo, "foo", req); int blah = (int)ServletDispatch.parseLongArg(3, "blah", req); String var = "not set"; String var = ServletDispatch.parseArg(var, "var", req); // ... return disp.dispatch(this, null); // Call out to next part of path } public static Object Args{ int count = 0; String name = null; int values[] = null; } public void Delete(ServletDispatch disp, HttpServletResponse res){ Args args = new Args(); disp.initArgObject(args); // ... } public boolean defaultDispatch(String method, ServletDispatch dispatch, Object context, HttpServletRequest req, HttpServletResponse res) { // ... }
com.mortbay.Util.ServletNode
,
com.mortbay.Util.ServletDispatchHandler
Constructor Summary | |
ServletDispatch(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
Constructor. |
Method Summary | |
java.lang.Object |
dispatch(java.lang.Object obj,
java.lang.Object context)
Dispatch the servlet request to a named method on the given object |
java.lang.String |
getProcessedPath()
|
java.lang.String |
getProcessedPathInfo()
|
void |
initArgObject(java.lang.Object toInit)
Initialise an arbitrary Object from the request parameters. |
static java.lang.Object |
parseArg(java.lang.Object defaultValue,
java.lang.String name,
javax.servlet.http.HttpServletRequest req)
Initialise an argument from the request parameters |
static boolean |
parseBooleanArg(boolean defaultValue,
java.lang.String name,
javax.servlet.http.HttpServletRequest req)
Version of parseArg to handle booleans |
static double |
parseDoubleArg(double defaultValue,
java.lang.String name,
javax.servlet.http.HttpServletRequest req)
Version of parseArg to handle doubles (and floats) |
static long |
parseLongArg(long defaultValue,
java.lang.String name,
javax.servlet.http.HttpServletRequest req)
Version of parseArg to handle longs (and short and int) |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public ServletDispatch(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
req
- res
- Method Detail |
public java.lang.Object dispatch(java.lang.Object obj, java.lang.Object context) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, java.lang.InstantiationException
obj
- The object to dispatch the request tocontext
- The context object to pass to the called function.public java.lang.String getProcessedPathInfo()
public java.lang.String getProcessedPath()
public static java.lang.Object parseArg(java.lang.Object defaultValue, java.lang.String name, javax.servlet.http.HttpServletRequest req)
E.g.
{ int foo[]; foo = (int[])ServletDispatch(foo, "foo", req); //...
defaultValue
- The default value to give the object (must be the
same type as the object, since it is used to determine the type to
convert the parameter to...)name
- The name of the parameterreq
- The requestpublic static long parseLongArg(long defaultValue, java.lang.String name, javax.servlet.http.HttpServletRequest req)
defaultValue
- If the param is not set or not parseablename
- Name of the paramreq
- The Requestpublic static double parseDoubleArg(double defaultValue, java.lang.String name, javax.servlet.http.HttpServletRequest req)
defaultValue
- If the param is not set or not parseablename
- Name of the paramreq
- The Requestpublic static boolean parseBooleanArg(boolean defaultValue, java.lang.String name, javax.servlet.http.HttpServletRequest req)
defaultValue
- If the param is not set or not parseablename
- Name of the paramreq
- The Requestpublic void initArgObject(java.lang.Object toInit)
toInit
- The object to initialise. If parameters exist
corresponding to the names of the public data members of this Object,
then they will be initialised.
E.g. public static Object Args{ int count = 0; String name = null; int values[] = null; } public void Add(ServletDispatch disp, HttpServletResponse res){ Args args = new Args(); disp.initArgObject(args); // ...
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |