servlet 向 jsp 页面传递参数

发布于 12-22 12:23 字数 337 浏览 0 评论 0原文

我必须将参数从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你怎么这么可爱啊2024-12-29 12:23:21

如果您从servlet转发到jsp,您应该设置为attribute do

request.setAttribute("key","value")

参数主要用于客户端与服务器的通信。并使用属性作为内部消息传递

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文