JSP中getAttribute和getParameter的不同

1.request  中对属性的操作,如果要使用 getAttribute( ) ,则之前一定要有setAttribute()的操作,否则无法取得。

2.使用 getParameter ( ) 则表示接收参数,参数的来源有:(1)表单提交(2)地址重写;getParameter ( )是无法接受setAttribute 所设置的属性的。

3.不同点:

(1)它们取到的值不同。getAttribute取到的是对象(object),而getParameter取到的是String。

(2)数据传递路径不同。request.getParameter方法传递的数据是从web客户端传到web服务器,代表http的请求数据,用于表单或url重定向时使用。而request.getAttribute方法传递的数据只存在于web容器内部,在具有转发关系的web组件之间共享(servlet和JSP),即在request范围内存在的对象。

(3)在jsp中,setAttribute()是把这个对象放到该页面所对应的一块内存中,当页面服务器转发到另一个页面时,应用服务器会把这块内存拷贝到另一块页面内存中,form表单默认提交过来的就是字符串

猜你喜欢

转载自blog.csdn.net/qq_32625839/article/details/63686267
今日推荐