在基于下拉选择获取查询结果时遇到问题,由于某种原因,它在尝试将其发布到 jsp 时没有返回任何内容。
这是我的代码的样子
这是我的 index.jsp
<form method="post" action="Test">
<h3>Get today's feed event</h3>
<p>
<select name="colour" size="1" class="selectpicker" data-style="btn-inverse">
<option value="light">Runningball</option>
<option value="amber">Enetpulse</option>
<option value="DonBest">DonBest</option>
<option value="BetRadar">Betradar</option>
</select>
</p>
<input type="submit" value="Submit" class="btn">
</form>
这是我的逻辑
public List<String> getColours(String colour) {
List<String> colours = new ArrayList<String>();
if(colour.equals("DonBest")){
try {
connectToCoral3();
CachedRowSet res1 = con.selectQuery(
"select id,name,event_time from nodes where syst_id=16 and event_time>=now() order by event_time");
//some debugging code
while (res1.next()) {
System.out.println("id= " + res1.getString("id") + " name= "
+ res1.getString("name"));
}
while (res1.next()) {
colours.add(res1.getString("id"));
colours.add(res1.getString("name"));
colours.add(res1.getString("event_time"));
}
} catch (Exception e) {
System.out.println(e.getStackTrace());
e.getStackTrace();
}
}else if(colour.equals("light")){
colours.add("orange");
colours.add("pink");
}
return (colours);
}
小服务程序
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
try {
String c = request.getParameter("colour");
ColourExpert ce = new ColourExpert();
List<String> styles = ce.getColours(c);
request.setAttribute("styles",styles);
System.out.println(styles);
} catch (Exception e) {
request.setAttribute("error", "Retrieving rows failed.");
e.printStackTrace();
}
RequestDispatcher view = request.getRequestDispatcher("WEB-INF/Home/simplePage.jsp");
view.forward(request, response);
这是我的jsp,
<c:forEach items="${styles}" var="styles">
<c:out value="${styles.id}" />
<c:out value="${styles.name}" />
<c:out value="${styles.event_time}" />
</c:forEach>
<c:if test="${not empty error}">Error: ${error}</c:if>
任何帮助都会很棒