servlet 向 jsp 页面传递参数
我必须将参数从servlet传递到jsp。我使用以下代码。是否可以通过这种方式传递参数?
String val="Testvalue"
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp?valpass=val");
dispatcher.forward(request, response);
在jsp中
String value=(String)request.getAttribute("valpass")
^
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")
^
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您从
servlet
转发到jsp,您应该设置为attribute
do参数主要用于客户端与服务器的通信。并使用属性作为内部消息传递
if you forward from
servlet
to jsp you should set asattribute
doparameter is mainly used in communicating with client to server. and use attribute as internal message passing