Servlet getinitparameter (), GetParameter (), getattribute () similarities and differences

Source: Internet
Author: User

Servletconfig#getinitparameter () acting on a single servlet

Servletcontext#getinitparameter () Acting on the global servlet

Scopes are different, but all need to be configured in Web. XML to return only the string type variable

Httpservletrequest#getparameter (): Gets the name value of the element in the form in the page, the client returns data to the server, and only the string type variable is returned

Httpservletrequest#setattribute () and getattribute () implement data retention in HttpServletRequest, which is used in a httpservletrequest life cycle. In the same servlet doget (), the DoPost () method and the JSP page pass parameters, the JSP page is made to convert.

ServletContext implements data sharing in Servlets under the same project through SetAttribute () and getattribute (), and all Servlets share a single ServletContext instance, singleton mode under the same project.

Both of these return values are object.

Reference reading:

Http://stackoverflow.com/questions/18490517/jsp-getattribute-returning-null

Http://stackoverflow.com/questions/5243754/difference-between-getattribute-and-getparameter

http://blog.csdn.net/liqinghuan_blog/article/details/11486017

Servlet getinitparameter (), GetParameter (), getattribute () similarities and differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.