Another example using hierarchies of actions: http://localhost:8989/admin/login.action is mapped to
org.utgenome.gwt.utgb.server.Login class.
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.utgenome.gwt.utgb.server.RequestDispatcher</servlet-class>
<init-param>
<param-name>base-package</param-name>
<param-value>(your web application request handler base package. e.g. org.utgenome.gwt.utgb.server.app)</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
Automatic Data Binding to Request Handler
Hello.java class has serveral parameter values name and year:
public class Hello implements RequestHandler {
private String name = "";
private int year = 2000;
public void handle(HttpServletRequest request, HttpServletResponse response) {
PrintWriter out = response.getWriter().println("Hello " + name + "(" + year + ")");
}
public void setName(String name) {
this.name = name;
}
public void setYear(int year) {
this.year = year;
}
}
Our RequestDispatcher
automatically set these parameter values from a given HTTP request. For example, an
HTTP request
http://localhost:8989/hello.action?name=leo&year=2007
will invoke setName("leo") and setYear(2007) methods.
Note that, although the query string in the HTTP request consists of string values, our BeanUtil
library
detects the data type to which the string should be translated by analysing the class definition. In this example,
the string value
"2007" is translated into an integer, 2007.
The web page result of the avobe request looks like as this:
Hello leo(2007)
Alternate access method: http://localhost:8989/dispathcer?actionClass=org.utgenome .gwt.utgb.server.app.hello&
- Author:
- leo
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RequestDispatcher
public RequestDispatcher()
removeGWTModuleNamePart
public static String removeGWTModuleNamePart(String requestURI)
setRequestParametersToHandler
public static void setRequestParametersToHandler(RequestHandler handler,
javax.servlet.http.HttpServletRequest req)
destroy
public void destroy()
- Specified by:
destroy
in interface javax.servlet.Filter
getExtension
public static String getExtension(String path)
doFilter
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain filterChain)
throws IOException,
javax.servlet.ServletException
- Specified by:
doFilter
in interface javax.servlet.Filter
- Throws:
IOException
javax.servlet.ServletException
dispatchRequest
public void dispatchRequest(RequestURI requestURI,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
javax.servlet.FilterChain filterChain)
throws IOException,
javax.servlet.ServletException
- Throws:
IOException
javax.servlet.ServletException
toInternetDateFormat
public static String toInternetDateFormat(long time)
- Converts a file-style date/time into a string form that is compatible with HTTP.
isGWTHostedMode
public static boolean isGWTHostedMode()
init
public void init(javax.servlet.FilterConfig config)
throws javax.servlet.ServletException
- Specified by:
init
in interface javax.servlet.Filter
- Throws:
javax.servlet.ServletException
initRequestMap
public void initRequestMap()
addRequestMap
public void addRequestMap(RequestMap map)
Copyright © 2007-2012 utgenome.org. All Rights Reserved.