Sto tentando di utilizzare un RequestDispatcher per inviare parametri da un servlet.Come inviare parametri da un servlet
Ecco il mio codice 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);
}
Ecco il mio jsp, con il codice per leggere il valore - tuttavia si vede nulla.
<h1>response 2</h1>
<p>
<%=request.getAttribute("myStation") %>
</p>
Grazie per eventuali suggerimenti. Greener
RequestDispatcher non viene utilizzato per leggere i parametri. Quindi ho modificato il tuo post. –