Servlet and Attribute Management in Java, Study Guides, Projects, Research of Web Application Development

An overview of servlets, their api, interfaces, and life cycle. It also covers the concept of attributes in servlets, their specific methods, and examples of setting and getting attributes using servletcontext. The document also explains the difference between servletconfig and servletcontext.

Typology: Study Guides, Projects, Research

2016/2017

Uploaded on 11/29/2017

rahul-r-21
rahul-r-21 🇮🇳

1 document

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
What is Servlet
Web T erminology
Servlet API
Servlet Interfac e
GenericSe rvlet
HttpSe rvlet
Servlet Life Cyc le
Servlet Example
How servlet works?
War File
welcome-f ile-list
Load on startup
Servlet w ith IDE
servlet in Eclipse
servlet in Myec lipse
servlet in Netbeans
ServletReque st
Servlet Collaboration
RequestDispacher
sendRedirec t
ServletConfig
ServletContex t
Attribute in Servlet
Servlet Tutorial
Servlet Advance
next →← prev
Attribute in Servlet
Attribute specific methods
Example of ServletContext to set and get
attribute
Difference between ServletConfig and
ServletContext
Attribute in Servlet
An attribute in servlet is an object that c an be set , get
or removed from one of the following scopes:
1. request scope
2. session scope
3. applicat ion scope
The servlet programmer c an pass informations from one
servlet to another using at tributes. It is just like passing
object from one c lass t o anot her so t hat we can reuse the same object again and again.
Attribute specific methods of ServletRequest, HttpSession and
ServletContext interface
Search on javatpoint...
Home
Core Java
Servlet
JSP
Struts2
Mail API
Hibernate
Android
Design Pattern
Quiz
Projects
Interview Q
Comment
PDFmyURL lets you convert a complete website to PDF automatically!
pf3
pf4
pf5
pf8

Partial preview of the text

Download Servlet and Attribute Management in Java and more Study Guides, Projects, Research Web Application Development in PDF only on Docsity!

What is Servlet Web Terminology Servlet API Servlet Interface GenericServlet HttpServlet Servlet Life Cycle Servlet Example How servlet works? War File welcome-file-list Load on startup Servlet with IDE servlet in Eclipse servlet in Myeclipse servlet in Netbeans ServletRequest Servlet Collaboration RequestDispacher sendRedirect ServletConfig ServletContext Attribute in Servlet

Servlet Tutorial

Servlet Advance

← prev next →

Attribute in Servlet

Attribute specific methods

Example of ServletContext to set and get

attribute

Difference between ServletConfig and

ServletContext

Attribute in Servlet

An attribute in servlet is an object that can be set, get or removed from one of the following scopes:

  1. request scope
  2. session scope
  3. application scope The servlet programmer can pass informations from one servlet to another using attributes. It is just like passing object from one class to another so that we can reuse the same object again and again.

Attribute specific methods of ServletRequest, HttpSession and

ServletContext interface

Search on javatpoint...

Home Core Java Servlet JSP Struts2 Mail API Hibernate Spring Android Design Pattern Quiz Projects Interview Q Comment

Session Tracking Session Techniques

  1. Cookies in Servlet Cookies: Login & Logout
  2. Hidden Form Field
  3. URL Rewriting
  4. HttpSession Session: Login & Logout Event and Listener Servlet Filter What is Filter Authentication Filter FilterConfig Useful examples Servlet CRUD CRUD Example Servlet Pagination Pagination Example Servlet Miscellaneous ServletInputStream ServletOutputStream Annotation Servlet SingleThreadModel SSI Development Registration Example Fetching records Improving Performance Uploading file Downloading file There are following 4 attribute specific methods. They are as follows:
  1. public void setAttribute(String name,Object object): sets the given object in the application scope.
  2. public Object getAttribute(String name): Returns the attribute for the specified name.
  3. public Enumeration getInitParameterNames(): Returns the names of the context's initialization parameters as an Enumeration of String objects.
  4. public void removeAttribute(String name): Removes the attribute with the given name from the servlet context. Example of ServletContext to set and get attribute In this example, we are setting the attribute in the application scope and getting that value from another servlet. DemoServlet1.java
  5. import java.io.*;
  6. import javax.servlet.*;
  7. import javax.servlet.http.*;
  8. public class DemoServlet1 extends HttpServlet{
  9. public void doGet(HttpServletRequest req,HttpServletResponse res)
  10. {
  11. try {
  12. res.setContentType("text/html");
  13. PrintWriter out=res.getWriter(); Ads by Adblade Foods That Cause Cancer This Food Causes Cancer According to the WHO and Americans Eat it Everyday! Is Bill Mad at Hillary? Divorce rumors are flying about the Clintons. Is it because Bill found out about THIS huge secret? Drink that Ruins a Smile Watch as this Drink Erodes a Tooth. You'll Never Believe the Reaction!
  1. out.println("Welcome to "+n);
  2. out.close();
  3. } catch (Exception e){out.println(e);}
  4. }} web.xml
  5. <web-app>
  6. <servlet-name>s1</servlet-name>
  7. <servlet- class >DemoServlet1</servlet- class >
  8. <servlet-mapping>
  9. <servlet-name>s1</servlet-name>
  10. <url-pattern>/servlet1</url-pattern>
  11. </servlet-mapping>
  12. <servlet-name>s2</servlet-name>
  13. <servlet- class >DemoServlet2</servlet- class >
  14. <servlet-mapping>

← prev next →

  1. <servlet-name>s2</servlet-name>
  2. <url-pattern>/servlet2</url-pattern>
  3. </servlet-mapping>
  4. </web-app> Difference between ServletConfig and ServletContext The servletconfig object refers to the single servlet whereas servletcontext object refers to the whole web application.

Next Topic Session Tracking in Servlets

LEARN TUTORIALS

Learn Java Tutorial

Learn C Tutorial

Learn C++ Tutorial

Learn C# Tutorial

Learn PHP Tutorial

Learn HTML Tutorial

Learn CSS Tutorial

Learn JavaScript Tutorial

Learn jQuery Tutorial

Learn Spring Tutorial

OUR WEBSITES

Javatpoint.com

Hindi100.com

Lyricsia.com

Quoteperson.com

Hindi-typing.com

Shayaree.com

Wordcountee.com

Charactercountee.com

Jobandplacement.com

OUR SERVICES

Website Development

Android Development

Website Designing

Digital Marketing

Summer Training

Industrial Training

College Campus Training

CONTACT

Address: G-13, 2nd Floor, Sec-

Noida, UP, 201301, India

Contact No: 0120-4256464,

Contact Us

Subscribe Us

Privacy Policy

Multivendor E-Commerce (Java) $18000 Approx

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at

[email protected].

Course Fee: ₹ 2000 Per Student

Like/Subscribe us for latest updates or newsletter

© Copyright 2011-2017 www.javatpoint.com. All rights reserved. Developed by SSS IT Pvt Ltd (JavaTpoint)