Version 7 (modified by 18 years ago) (diff) | ,
---|
UTGB Request Dispatcher Mechanism
web.xml setting
Add the following description into your web.xml.
- The lines param-name=base-package, param-value=(application base) specifies the location (base package name) where the RequestDispatcher searches recursively for RequestHandler? implementations.
- With the following setting, an HTTP request, e.g., http://localhost:8989/hello.action, is mapped to the request handler org.utgenome.gwt.utgb.server.app.Hello class. The upper letters are converted into the lower letters when mapping the request, e.g., Hello action can be accecced via hello.action URL.
- 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)
Using Dispatcher in GWT Hosted Mode
Unfortunately, GWT-hosted mode that uses gwt-embedded TomcatServer? and GWTShell, does not support servlet-mapping in web.xml, since every path (/*) is already mapped to GWTShellServlet, which redirects requests to public folder or servlet codes.
GWTShellServlet is mandatory to debug client-side codes within within Eclipse (or other IDEs).
Thus, there is no way to use following web.xml setting effectively.
<url-pattern>*.action</url-pattern>
Even if you put the avobe setting into tomcat/ROOT/WEB-INF/web.xml, it does not work because of the mapping /* to GWTShellServlet overshadows other mappings.