is it possible to return ResultSet variable to JSTL foreach tag? I am getting null point error and for the wrong reason, it's saying that db2.MyServ class doesn't exist even though its right there. anyone know what i'm doing wrong and how to itterate over my ResultSet rs on jstl?
MyServ2 class(imports etc omitted)
package db2;
public class MyServ2 extends HttpServlet {
private static final long serialVersionUID = 1L;
private DBClass db;
private ResultSet rs;
public MyServ2() {
super();
db = new DBClass();
db.dbConnect("jdbc:oracle:thin:@elanweb:1510:xxxxx", "xxxxx", "xxx");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
rs = db.getResultSet(request.getParameter("query"));
try {
while(rs.next()){
System.out.println(rs.getString(1).toString());
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet getRs()
{
return rs;
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="db2.MyServ2" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
</head>
<body>
successful login
<jsp:useBean id="myserv2" class="db2.MyServ2"/>
<c:if test="${myserv2.rs.Next()}">
<c:forEach var="person" items="${myserv2.rs}">
<c:out value="${myserv2.rs.string(1).toString()}"></c:out>
</c:forEach>
</c:if>
</body>
</html>
I've created a bean and saved strings to it. When i call them from my MyServ2 class for debugging, they work fine, but when i call them from my webpage as jstl they return null as if the bean is no populated. Does everything reset as soon as i redirect back to the webpage?
<jsp:useBean id="mybean" class="beans.UserBean"></jsp:useBean>
<c:out value="${mybean.name}"></c:out><br></br>
added in MyServ class the following
rs = db.getResultSet(request.getParameter("query"));
try {
while(rs.next()){
mybean.SetName(rs.getString(1).toString());
mybean.Setsurname( rs.getString(2).toString());
}
} catch (SQLException e) {
e.printStackTrace();
}