以下は、サーブレットとjspファイルのコードです
Connect.java
@WebServlet("/calendar")
public class Connect extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fromDate = request.getParameter("fromDate");
String toDate = request.getParameter("toDate");
String query = "SELECT action_time,user_action,user_ip,user_id FROM di.login_detail where (action_time, action_time) OVERLAPS (DATE '"
+ fromDate+ "',DATE '"+ toDate+ "'+ integer '1')" +
" order by action_time desc";
Connection conn = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
System.out.println("done4");
try {
conn = ConnectionUtil.getConnection();
statement = conn.prepareStatement(query);
resultSet = statement.executeQuery();
if (resultSet.next()) {
while(resultSet.next()){
String action_time=resultSet.getString("action_time");
String user_action=resultSet.getString("user_action");
String user_ip=resultSet.getString("user_ip");
String user_id=resultSet.getString("user_id");
request.setAttribute("action_time",action_time);
request.setAttribute("user_action",user_action);
request.setAttribute("user_ip",user_ip);
request.setAttribute("user_id",user_id);
RequestDispatcher view = request.getRequestDispatcher("calendar.jsp");
view.forward(request,response);
}
} else {
System.out.println("not found");
}
} catch (SQLException e) {
throw new ServletException("DB interaction failed", e);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (resultSet != null) try { resultSet.close(); } catch (SQLException ignore) {}
if (statement != null) try { statement.close(); } catch (SQLException ignore) {}
if (conn != null) try { conn.close(); } catch (SQLException ignore) {}
}
}
}
Calendar.jsp
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script src="<%=path%>/js/calendar.js"></script>
<link href="<%=path %>/css/calendar.css" rel="stylesheet">
</head>
<body>
<form action="calendar">
<div class="container">
From:<input name="fromDate" type="text" class="calendarSelectDate" />
To: <input name="toDate" type="text" class="calendarSelectDate" />
<input type="submit" name="b1" value="Go">
</div>
<div id="calendarDiv"></div>
<%= request.getAttribute("action_time")%>
<%= request.getAttribute("user_action")%>
<%= request.getAttribute("user_ip")%>
<%= request.getAttribute("user_id")%>
</form>
</body>
</html>
サーブレットから calender.jsp に結果を表示しようとしています。上記で渡されたクエリは結果として複数の行を生成しますが、jsp ページでは最初の行の出力のみを生成し、実行を停止します。jspで完全な結果を取得するために、ここで他に何ができるでしょうか。ありがとうございました////