getParameter()和getAttribute()

来源:互联网 发布:巧手十字绣软件 编辑:程序博客网 时间:2024/06/18 07:18

JSP中getParameter和getAttribute

在JSP代码中:

${param.name}

等同于

<%    request.getParameter("name");%>

一般用于服务器从页面或者客户端获取的内容。
如表单提交数据或者url地址栏 ?name=”name”;

${requestScope.name} 

等同于

<%    request.getAttribute("name");%>

一般是从服务器传递结果到页面,在页面中取出服务器保存的值。
如servlet中request.setAttribute(“name”,”value”);

API 说明:

java.lang.String getParameter(java.lang.String name)

Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

void setAttribute(java.lang.String name, java.lang.Object o)
Stores an attribute in this request.