将参数从servlet传递到jsp页面 [英] pass parameters from servlet to jsp page

查看:349
本文介绍了将参数从servlet传递到jsp页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将参数从servlet传递到jsp .Iam使用以下代码.是否可以通过这种方式传递参数?

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); 

在jsp中

String value=(String)request.getAttribute("valpass") ^

推荐答案

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

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

这篇关于将参数从servlet传递到jsp页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆