【发布时间】:2009-09-10 18:58:47
【问题描述】:
我正在尝试使用 RequestDispatcher 从 servlet 发送参数。
这是我的 servlet 代码:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String station = request.getParameter("station");
String insDate = request.getParameter("insDate");
//test line
String test = "/response2.jsp?myStation=5";
RequestDispatcher rd;
if (station.isEmpty()) {
rd = getServletContext().getRequestDispatcher("/response1.jsp");
} else {
rd = getServletContext().getRequestDispatcher(test);
}
rd.forward(request, response);
}
这是我的 jsp,带有读取值的代码 - 但是它显示为 null。
<h1>response 2</h1>
<p>
<%=request.getAttribute("myStation") %>
</p>
感谢您的任何建议。 更环保
【问题讨论】:
-
RequestDispatcher 不用于读取参数。因此我编辑了你的帖子。