后台数据传到前台

后台代码

 @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {

        PersonDaoImpl pdi = new  PersonDaoImpl();
        List<Person> li = pdi.getResult();
        System.out.println(li);
        request.setAttribute("values", li);
        request.getRequestDispatcher("index.jsp").forward(request, response);


    }

前台代码:

<%

    System.out.println(request.getAttribute("values"));

%>

getAttribute:以Object的形式返回指定属性的值;如果不存在指定名称的属性,则返回null。
属性可以通过两种方式设置。 servlet容器可以设置属性以提供关于请求的可用定制信息。 例如,对于使用HTTPS进行的请求,可以使用属javax.servlet.request.X509Certificate来检索客户端证书上的信息。 也可以使用ServletRequest.setAttribute以编程方式设置属性。 这允许
要在RequestDispatcher调用之前嵌入到请求中的信息。
属性名称应遵循与包名称相同的约定。 这个规范
保留与java。,javax。和sun。*匹配的名称。
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using ServletRequest.setAttribute. This allows
information to be embedded into a request before a RequestDispatcher call.
Attribute names should follow the same conventions as package names. This specification
reserves names matching java., javax., and sun.*.
public void setAttribute(java.lang.String name,
java.lang.Object o)

Stores an attribute in this request. Attributes are reset between requests. This method is most often used in conjunction with RequestDispatcher.

Attribute names should follow the same conventions as package names. Names beginning with java.*, javax.*, and com.sun.*, are reserved for use by Sun Microsystems.
If the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String).
It is warned that when the request is dispatched from the servlet resides in a different web application by RequestDispatcher, the object set by this method may not be correctly retrieved in the caller servlet.

Parameters:
    name - a String specifying the name of the attribute
    o - the Object to be stored
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helloworddm

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值