Request Handlers
To handle requests, you need to implement the RequestHandler interface. The handleRequest() method gets the session, request, and response objects as parameters.
In the following example, we catch requests for a sub-path in the URL for the servlet and write a plain text response. The servlet path consists of the context path and the servlet (sub-)path. Any additional path is passed to the request handler in the pathInfo of the request. For example, if the full path is /myapp/myui/rhexample, the path info will be /rhexample. Also, request parameters are available.
A request handler can be used by embedding it in a page or opening a new page with a link or a button. In the following example, we pass some data to the handler through a session attribute.
TextField dataInput = new TextField("Some data");
dataInput.addValueChangeListener(event ->
VaadinSession.getCurrent().setAttribute("mydata",
event.getProperty().getValue()));
// Determine the base path for the servlet
String servletPath = VaadinServlet.getCurrent()
.getServletContext().getContextPath()
+ "/book"; // Servlet
Link open = new Link("Click to Show the Page",
new ExternalResource(servletPath + "/rhexample"),
"_blank", 500, 350, BorderStyle.DEFAULT);