使用RequestDispatcher发送变量值的问题

时间:2011-06-26 10:19:18

标签: java jsp servlets

在变量search_for中,我得到了我正在搜索的值的字符串值。但是我无法通过RequestDispatcher将它传递给jsp。我做错了什么?

RequestDispatcher rd = request.getRequestDispatcher("my.jsp?search_for"); 

1 个答案:

答案 0 :(得分:3)

Soution 1:

request.setAttribute("paramName", search_for);
RequestDispatcher rd = request.getRequestDispatcher("my.jsp");
rd.forward(request, response);

Soution 2:

RequestDispatcher rd = request.getRequestDispatcher("my.jsp?paramName="+search_for);
rd.forward(request, response);