[英]pass parameters from servlet to jsp page
I have to pass parametrs From servlet to jsp .Iam using the following code.Is it possible to pass parameters through this way? 我必须使用以下代码将参数从servlet传递到jsp .Iam。是否可以通过这种方式传递参数?
String val="Testvalue"
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp?valpass=val");
dispatcher.forward(request, response);
In jsp 在jsp中
String value=(String)request.getAttribute("valpass")
^ String value=(String)request.getAttribute("valpass")
^
if you forward from servlet
to jsp you should set as attribute
do 如果你从servlet
转发到jsp你应该设置为attribute
do
request.setAttribute("key","value")
parameter is mainly used in communicating with client to server. 参数主要用于与客户端到服务器的通信。 and use attribute as internal message passing 并使用属性作为内部消息传递
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.