내 프로젝트에서 데이터베이스의 쿼리 결과를 내 서블릿으로 가져오고 ResultSet
에 대한 속성을 설정 한 다음 결과를 JSP로 전달한 다음 JSP로 액세스합니다.하지만 어떻게 든 ResultSet을 제외하고 JSP와 서블릿에서 다른 모든 속성을 설정하고 액세스 할 수 있습니다.Servlet에서 ResultSet의 속성을 설정할 수 없습니다
res=accessDB.getCart(it,ci);
request.setAttribute("cart",res);
view=request.getRequestDispatcher("cart.jsp");
view.forward(request, response);
을 내가 무엇을 잘 모릅니다 : 그래서 여기
는 서블릿 스 니펫되고 여기에 JSP
<%ResultSet r=(ResultSet)request.getAttribute("cart");%>
<div id="pageContent">
<div style="margin:24px; text-align:left;"><br />
<table width="100%" border="2" cellspacing="0" id ="table1">
<tr>
<td width="15%" bgcolor="#000000" align="center"><strong>Product</strong></td>
<td width="10%" bgcolor="#000000" align="center"><strong>Price</strong></td>
<td width="12%" bgcolor="#000000" align="center"><strong>Quantity</strong></td>
<!--<td width="9%" bgcolor="#000000" align="center"><strong>Total</strong></td>-->
</tr>
<%while(r.next()){%>
<tr class="spaceUnder">
<td width="15%" bgcolor="#FFFFFF" align="center"><font color="#000"> <%=re.getString(1)%></font></td>
<td width="10%" bgcolor="#FFFFFF" align="center"><font color="#000"> <%=re.getInt(2)%></font></td>
<td width="12%" bgcolor="#FFFFFF" align="center"><font color="#000"> <%=re.getInt(3)%> </font></td>
</tr>
<%}%>
</table>
<div class="container">
<left><h3 style="color:#FFFFF;padding-top:30px;"><font color="#000">Total: <%=total%> </font></h3></left>
</div>
</div>
</div>
이며, 여기 내 데이터베이스 액세스 기능의 getCart()
public static ResultSet getCart(int item,int cust){
ResultSet rs=null,res=null;
String i_name;
int price;
try{
rs=stmnt.executeQuery("SELECT i_name,price FROM items WHERE i_id="+item);
rs.next();
i_name=rs.getString(1);
price=rs.getInt(2);
stmnt.executeUpdate("INSERT INTO cart(prod,price,c_id,i_id) VALUES('"+i_name+"',"+price+","+cust+","+item+")");
res=stmnt.executeQuery("SELECT prod,price,count(*) FROM cart WHERE c_id="+cust+" GROUP BY i_id");
res.next();
}catch(SQLException e){}
return res;
}
입니다 이 일어나고있다?? 이제는 이것에 많은 시간을 보냈습니다. 그리고 데이터베이스가 비어 있지 않습니다. 그래서 res.next()가 유효합니다.
한 가지 내가 getInt
및 getString
를 사용하여 내 서블릿 코드에서 내 ResultSet
을 분해 working.When이며, 다음 JSP에 다음을 보내 개별적으로 대신 작동 JSP에서 전체 ResultSet
, 다음 getAttribute
를 보내고 난 내 결과를 인쇄 할 수 있습니다. 하지만 전체가 ResultSet
이 아닌 이유를 모르겠습니다. Netbeans 8.0.1을 사용하고 있습니다.
도와주세요.
'session.setAttribute ("cart", res);'(request.getSession(). setAttribute ("cart");'를 실행하여 HttpSession을 얻을 수있다. JSP처럼'session.getAttribute ("cart");'와 같은 검색 후 JSP에서 세션에서 그것을 제거하십시오. – brso05
당신은 결과 집합을 사용해서는 안됩니다. – Hannes
JVM에서 메모리 누수를 속일 방법을 찾고 있습니까? 네가 성공했기 때문에. –