want to fill a textbox dynamically in jsp page

前端 未结 1 1366
庸人自扰
庸人自扰 2021-01-16 13:41

want to create a application using jsp pages such that it takes a value from user in a textbox and on the basis of that value it retrives other values from database and fill

1条回答
  •  春和景丽
    2021-01-16 14:35

    1. Create a HTML form and put it in search.jsp:

    2. Create a Java class which extends HttpServlet and does the desired business task:

      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          String query = request.getParameter("query");
          Data data = someDAOClass.find(query);
          request.setAttribute("data", data); // Will be available in EL by ${data}
          request.getRequestDispatcher("search.jsp").forward(request, response); // Return back to JSP page.
      }
      

      Map this servlet on an url-pattern of /search in web.xml so that it will be executed then the form in the JSP is submitted.

    3. Extend the form with the input fields which should display this data. Just fill the value attribute of the input elements with the desired information.

      ...

      The fn:escapeXml is by the way there to prevent XSS.

    0 讨论(0)
提交回复
热议问题