在 Hasor Web 中使用 Servlet 如下所示,首先編寫(xiě)我們自己的 HttpServlet,然后將它注冊(cè)到 Hasor 中:
public class DemoHttpServlet extends HttpServlet{
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
...
}
}
第一種方式 Api 接口注冊(cè) Servlet 的地址。
public class DemoModule extends WebModule{
public void loadModule(WebApiBinder apiBinder) throws Throwable {
apiBinder.jeeServlet("/your_point.do").with(DemoHttpServlet.class);
}
}
第二種方式,通過(guò) @MappingTo 注冊(cè) Servlet,如下:
@MappingTo("/your_point.do")
public class DemoHttpServlet extends HttpServlet{
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
...
}
}
掃描所有 @MappingTo
public class DemoModule extends WebModule{
public void loadModule(WebApiBinder apiBinder) throws Throwable {
apiBinder.scanMappingTo();
}
}
更多建議: