当我使用session.setAttribute(-)
或request.setAttribute(-)
时,我的Servlet不会转发到我的JSP。
只有当session / request.setAttribute( - )代码被注释但我需要将数据从Servlet发送到JSP时,才会发送Servlet。谁能告诉我:
的Servlet
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
//1 - Get bank transaction records : transacRecords is a ResulSet object to be used in the JSP
transacRecords=getTransactionRecords();
//2 - Put them in a session object
//HttpSession session = request.getSession(true);
//session.setAttribute("BankTransaction", transacRecords);
//request.setAttribute("BankTransaction", transacRecords);
//3 - Forward to bank transaction view
RequestDispatcher dispatcher = request.getRequestDispatcher("/viewBanqueTransaction.jsp");
dispatcher.forward(request,response);
}
viewBanqueTransaction.jsp
<%@ page language="java" session="true"%>
<%@ page language="java" import="java.util.*"%>
<%@ page language="java" import="java.sql.ResultSet"%>
<%
ResultSet BankTransaction = (ResultSet)request.getAttribute("BankTransaction");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<body>
Hello world !!
</body>
</html>
答案 0 :(得分:0)
由于“BalusC”评论,问题解决了。 将ResultSet放在请求对象中是原因。 Meaby因为这种对象指向DB。所以,当我把一个字符串向前推进时。 谢谢大家的意见。
此帖子了解更多信息Resultset in session