【问题标题】:how to send 1 textbox value to more than 1 servlet [duplicate]如何将 1 个文本框值发送到 1 个以上的 servlet [重复]
【发布时间】:2019-12-24 07:27:51
【问题描述】:

我有一个 .jsp 页面,其中有 1 个文本框和 4 个按钮,就像这张图片一样。我的项目创建 ms word 文档报告。它从访问数据库中获取数据。

我想在每次单击按钮时运行不同的 servlet,但我不知道该怎么做?有什么想法吗?

【问题讨论】:

    标签: jsp servlets


    【解决方案1】:

    您可以通过多种方式做到这一点,这是一个示例

     <form action="MainServlet" method="Post">
            SOME Name: <input type="text" name="someName" size="20">
            <br><br>
            <input type="submit" name="first" value="FirstServlet">
            <input type="submit" name="second" value="SecondServlet">
            <input type="submit" name="third" value="ThirdServlet">
            <input type="submit" name="fourth" value="FourthServlet">
        </form>
    
        with the following in MainServlet
    
        String sometext = request.getParameter("someName"); // your text box value
        if (request.getParameter("first") != null) {
            // Invoke FirstServlet's job here.
        } else if (request.getParameter("second") != null) {
            // Invoke SecondServlet's job here.
        } else if (request.getParameter("third") != null) {
            // Invoke ThirdServlet's job here.
        } else if (request.getParameter("fourth") != null) {
            // Invoke FourthServlet's job here.
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 2020-02-08
      • 2013-11-11
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多