调用session.setAttribute或request.setAttribute时,Servlet不转发到jsp

时间:2011-11-30 23:43:14

标签: servlets

当我使用session.setAttribute(-)request.setAttribute(-)时,我的Servlet不会转发到我的JSP。

只有当session / request.setAttribute( - )代码被注释但我需要将数据从Servlet发送到JSP时,才会发送Servlet。谁能告诉我:

  1. 我的代码出了什么问题,
  2. 为什么使用会话/请求会阻止转发?
  3. 的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>
    

1 个答案:

答案 0 :(得分:0)

由于“BalusC”评论,问题解决了。 将ResultSet放在请求对象中是原因。 Meaby因为这种对象指向DB。所以,当我把一个字符串向前推进时。 谢谢大家的意见。

此帖子了解更多信息Resultset in session