我的任务是需要在Vaadin应用程序中处理一个post请求这是一个需要处理的请求示例
我不明白如何在Vaadin我可以得到POST或get请求我还找到了关于创建servlet 3.0应用程序的文档——没有找到vadin v23
@Route("/")
@CssImport("./styles/shared-styles.css")
@CssImport(value = "./styles/vaadin-text-field-styles.css", themeFor = "vaadin-text-field")
@Log4j2
public class MainView extends VerticalLayout {
...
public MainView() {
// VaadinSession.getCurrent().addRequestHandler(
// new RequestHandler() {
// @Override
// public boolean handleRequest(VaadinSession session,
// VaadinRequest request,
// VaadinResponse response)
// throws IOException {
// if ("/notifications".equals(request.getPathInfo())) {
// // Generate a plain text document
// response.setContentType("text/plain");
// response.getWriter().append(
// "Here's some dynamically generated content.n");
// response.getWriter().format(Locale.ENGLISH,
// "Time: %Tcn", new Date());
//
// // Use shared session data
// response.getWriter().format("Session data: %sn",
// session.getAttribute("mydata"));
//
// return true; // We wrote a response
// } else
// return false; // No response was written
// }
// });
}
@WebServlet(value = "/notifications", asyncSupported = true)
public static class Servlet extends VaadinServlet {
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
VaadinServlet servlet = getService().getServlet();
}
}
调用http://localhost:8080/notifications时我得到了
Could not navigate to 'notifications'
在注释代码的帮助下,我设法进入请求处理程序,但我怀疑这是正确的方法
// VaadinSession.getCurrent().addRequestHandler(
// new RequestHandler() {
// @Override
// public boolean handleRequest(VaadinSession session,
// VaadinRequest request,
// VaadinResponse response)
// throws IOException {
// if ("/notifications".equals(request.getPathInfo())) {
// // Generate a plain text document
// response.setContentType("text/plain");
// response.getWriter().append(
// "Here's some dynamically generated content.n");
// response.getWriter().format(Locale.ENGLISH,
// "Time: %Tcn", new Date());
//
// // Use shared session data
// response.getWriter().format("Session data: %sn",
// session.getAttribute("mydata"));
//
// return true; // We wrote a response
// } else
// return false; // No response was written
// }
// });
我还找到了关于创建servlet 3.0应用程序的文档- Vaadin v23没有找到
这应该仍然可以工作,所以您可以将应用程序映射到例如。http://localhost:8080/app/*这样Vaadin就不会干扰http://localhost:8080/notifications