Package io.github.jirkasa.servletrouter
Class HttpRouter
java.lang.Object
io.github.jirkasa.servletrouter.Router<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
io.github.jirkasa.servletrouter.HttpRouter
- All Implemented Interfaces:
Handler<javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse>
public class HttpRouter
extends Router<javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse>
Implementation of
Router
that uses HttpServletRequest and HttpServletResponse.
It can be created directly like this:
HttpRouter router = new HttpRouter(); router.register("/", HomeController.class); router.register("/info", infoRouter);or a subclass can be created (which is recommended) and register methods can be called from the constructor:
public class AppRouter extends HttpRouter { public AppRouter() { register("/", HomeController.class); register("/info", infoRouter); } }
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
getRequestPath
(javax.servlet.http.HttpServletRequest request) This method is called by implementation of handle method to get request path.Methods inherited from class io.github.jirkasa.servletrouter.Router
handle, matchesFullPath, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, register, registerErrorController, setPathParams
-
Constructor Details
-
HttpRouter
public HttpRouter()
-
-
Method Details
-
getRequestPath
Description copied from class:Router
This method is called by implementation of handle method to get request path.- Specified by:
getRequestPath
in classRouter<javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse> - Parameters:
request
- Request based on which should be determined request path.- Returns:
- Request path without leading and trailing slashes. For example "info/about" (not
"/info/about/").
-