0

我有这个表格,这样做的目的是过滤jsp页面中的数据。这很有效,但我认为这很简单而且不好,而且仅适用于 2013 年,我想让它增加。有没有更好更简单的方法来做到这一点?

<% 
String First = request.getParameter("firstTo");
String Second = request.getParameter("secondTo");

request.setAttribute("First", First);
request.setAttribute("Second", Second);

Connection conn = (Connection) this.getServletContext().getAttribute("conn");
String query = "SELECT * FROM blood_chemistry JOIN consult USING (idconsult) JOIN patients USING (idpatients) WHERE release_date BETWEEN '" + First + "' AND '" + Second + "'  ORDER BY plastname ASC, pfirstname ASC";
PreparedStatement ps = conn.prepareStatement(query);
ResultSet rs = ps.executeQuery(); 
%>

<form method="post" action="blood.jsp">
<p style="color:white;">
    <select name="firstTo">
       <option value="01-01-2013">January</option>
       <option value="02-01-2013">February</option>
       <option value="03-01-2013">March</option>
       <option value="04-01-2013">April</option>
       <option value="05-01-2013">May</option>
       <option value="06-01-2013">June</option>
       <option value="07-01-2013">July</option>
       <option value="08-01-2013">August</option>
       <option value="09-01-2013">September</option>
       <option value="10-01-2013">October</option>
       <option value="11-01-2013">November</option>
       <option value="12-01-2013">December</option>
   </select>To:
   <select name="secondTo">
       <option value="01-31-2013">January</option>
       <option value="02-29-2013">February</option>
       <option value="03-31-2013">March</option>
       <option value="04-31-2013">April</option>
       <option value="05-31-2013">May</option>
       <option value="06-31-2013">June</option>
       <option value="07-31-2013">July</option>
       <option value="08-31-2013">August</option>
       <option value="09-31-2013">September</option>
       <option value="10-31-2013">October</option>
       <option value="11-31-2013">November</option>
       <option value="12-31-2013">December</option>
   </select>
</p></form>

我设法做到了,但这只是当前日期,我想将其设置为 2013 年 1 月 1 日,但年份只会增加.. 我该怎么做?

<%
  Date dNow = new Date( );
  SimpleDateFormat ft = 
  new SimpleDateFormat ("MM--dd--yyyy");
  out.print( "<h1 align=\"center\">" + ft.format(dNow) + "</h1>");
%>
4

1 回答 1

0

如果你只想要年份动态,你可以这样做

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
System.out.println(calendar.get(Calendar.YEAR));
于 2013-11-02T19:47:00.347 回答