问题
I have to pass parametrs From servlet to jsp .Iam using the following code.Is it possible to pass parameters through this way?
String val="Testvalue"
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp?valpass=val");
dispatcher.forward(request, response);
In jsp
String value=(String)request.getAttribute("valpass") ^
回答1:
if you forward from servlet to jsp you should set as attribute do
request.setAttribute("key","value")
parameter is mainly used in communicating with client to server. and use attribute as internal message passing
来源:https://stackoverflow.com/questions/8613389/pass-parameters-from-servlet-to-jsp-page