日期作为jsp页面中的输入

时间:2018-04-03 10:43:30

标签: jsp

我想在我的jsp页面上创建一个输入字段,它以日期作为输入。我希望该字段有3个不同的日期,月份和年份下拉列表,其中日期的值可以是1到31,月份可以是1月到12月,年份可以是2018到几年。请帮助我实现这一目标。

1 个答案:

答案 0 :(得分:0)

您应该使用日期时间选择器,而不是拥有3个组合框。默认情况下,JSP使用HTML 4,因此不要忘记使JSP HTML 5兼容。写下

<!DOCTYPE html>
    <html>
    <body>

    <h2>Date Field</h2>
    <p>The <strong>input type="date"</strong> is used for input fields that should contain a date.</p>
    <p>Depending on browser support:<br>A date picker can pop-up when you enter the input field.<p>

    <form action="/abc.jsp">
      Birthday:
      <input type="date" name="bday">
      <input type="submit">
    </form>

    </body>
    </html>

enter image description here

当您创建新的JSP页面时,会自动生成一些代码,如下所示:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

编辑第二行。保持第二个像这样的代码