【问题标题】:Getting textbox values using JSP使用 JSP 获取文本框值
【发布时间】:2011-09-02 07:48:10
【问题描述】:

我是使用 JSP 的新手,我需要通过单击按钮从文本框中获取值。我将 Java Netbeans 与服务器 apache tomcat 一起使用。这就是它的工作原理......

文本框包含在 HTML 标记 <table> 中,一旦用户输入一个值,他单击按钮,然后会出现一个消息框,其中包含他输入的值。

我不熟悉 JSP,这让我很难受。

【问题讨论】:

  • 你能贴一些你工作过的代码sn-p

标签: java jsp servlets jakarta-ee


【解决方案1】:

你需要在web.xml中配置一个servlet

创建一个表单并将日期发布到该 servlet

这里我已经概述了它的外观

你的 JSP

<form action"/yourServlet" method ="post">
<input type="text" name="age"/>
<input type="SUBMIT" />
</form>

您的 Servlet

doPost(....){
  String age = request.getParameter("age");
}

必看

【讨论】:

    【解决方案2】:

    我的答案对第一个答案很熟悉。

    mainPage.jsp

    <html>
      <head>
        <title>Your Title Here</title>
      </head>
      <body>
        <form action="sample.jsp" method="POST">
          <input type="text" id="firstname" name="firstname" />
          <input type="submit" value="Submit" />
        </form>
      </body>
    </html>
    

    sample.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%
        String firstname = request.getParameter("firstname");
        /* 
         * Some code here
         */
    %>
    

    我也在使用 apache tomcat。

    您必须按照第一个答案中的说明配置您的 web.xml。

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多