Attributes in Servlet

Click to rate this post!
[Total: 0 Average: 0]

Attributes in Servlet:

  1. A quality in servlet is a protest that can be set, get or expelled from one of the accompanying extensions request scope
  2. session scope
  3. application scope

The servlet software engineer can pass informations starting with one servlet then onto the next utilizing properties. It is much the same as passing item starting with one class then onto the next so we can reuse a similar question over and over.

         Methods:
  1. public void setAttribute(String name,Object object)
  2. public Object getAttribute(String name)
  3. public Enumeration getInitParameterNames()
  4. public void removeAttribute(String name)

Example:

DemoServlet1.java :

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class DemoServlet1 extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res)

{

try{

res.setContentType(“text/html”);

PrintWriter out=res.getWriter();

ServletContext context=getServletContext();

context.setAttribute(“company”,”IBM”);

out.println(“Welcome to first servlet”);

out.println(“<a href=’servlet2′>visit</a>”);

out.close();

}catch(Exception e){out.println(e);}

}}

DemoServlet2.java :

imort java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class DemoServlet2 extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res)

{

try{

res.setContentType(“text/html”);

PrintWriter out=res.getWriter();

ServletContext context=getServletContext();

String n=(String)context.getAttribute(“company”);

out.println(“Welcome to “+n);

out.close();

}catch(Exception e){out.println(e);}

}}

JAVA Tutorial Video

web.xml:

<web-app>

<servlet>

<servlet-name>s1</servlet-name>

<servlet-class>DemoServlet1</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>s1</servlet-name>

<url-pattern>/servlet1</url-pattern>

</servlet-mapping>

<servlet>

<servlet-name>s2</servlet-name>

<servlet-class>DemoServlet2</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>s2</servlet-name>

<url-pattern>/servlet2</url-pattern>

</servlet-mapping>

</web-app>

Attributes :

sets the given protest in the application scope.

open Object getAttribute(String name):Returns the trait for the predetermined name.

open Enumeration getInitParameterNames():Returns the names of the setting’s introduction parameters as an Enumeration of String objects.

open void removeAttribute(String name):Removes the trait with the given name from the servlet setting.

 

 

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.

  • python training
    Python Certification Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.


100% Secure Payments. All major credit & debit cards accepted.

Call Now Button