# data[].attributes.attachment_link.description
See all the wonderful things MOHAMMAD NOOR BIN IBRAHIM has made

# data[].attributes.attachment_link.keywords[]
multi-user database
              management system

# data[].attributes.attachment_link.title
Creating a Simple Web Application Using a MySQL Database - NetBeans IDE Tutorial

# data[].attributes.attachment_link.description
A tutorial describing how to create a simple, two-tiered web application that connects to a MySQL database in NetBeans IDE

# data[].attributes.attachment_link.readable_text
In this article we discuss how to create a JSP web page in the Netbeans IDE 7.4 using the Tomcat Server 7.0.40.
To create a JSP web page in the Netbeans IDE we must do the following three main steps:

1. Start by creating a "Java web" -> "web application project".

2. Create a JSP web file.

3. Last and finally, start the Tomcat Server and deploy the project.

Step 1: Start creating web application project Step 1(a)
Open the Netbeans IDE to start your project.
Step 1(b)
Now click on file menu and select New Project then select Java Web and then Web Application as follows.

From the file menu select "New Project" -> "Java Web" -> "Web Application" as in the following figure:
Step 1(c)
Now click on "Next". A new window is generated with a default project name. Now change the name (I used "JspWebApplication") according to your project and click on "Next".

As in the following figure:
Step 1(d)
Now a new window is generated for the server and setting the wizard. First go to the server and click on "Add server". Since I already set up the Tomcat Server, it is shown there but when you do it the first time it shows blank, see the image below.
Step 1(e): Server and Setting wizard First you need to configure Apache Tomcat Server 7.0.40
For configuration of the Tomcat Server follow my previous article from the following link:

http://www.c-sharpcorner.com/UploadFile/fd0172/how-to-configure-and-install-apache-tomcat-server-in-windows/

After clicking on Add, a list of servers opens. In this article I used Tomcat Server 7.0.40. Choose your server and configure it. For Tomcat Server choose it (Apache Tomcat on screen) and click on "Next". Now a window opens asking for the server location. Now, click on the Browse button and find the server location where you have stored the Apache Tomcat Server (in my system it is in "E:\myserver\tomcat7.0.40\bin"). Note that you need to provide the path up to the bin directory of Tomcat Server. As in the following:
Step 1(f)
After providing the server path you will see two more options for username and password. It's your choice whether you want your username and password or you want the default created by the Netbeans IDE. Now click on "Finish".

Now a window is generated containing the default index.jsp file in Web Pages under JspWebApplication. As in the following:
Step 2: Create a JSP Page.
Now change some coding in the default JSP page as given below.
index.jsp
Change the title: JSP Web Page

Change the heading: "Welcome To The JSP Web World!" as in the following:
Step 3: Run The Project using Tomcat Server. Step 3(a)
First recheck the Tomcat configuration if you have changed the default port number of Apache Tomcat then you need to do the same in the Netbeans IDE.

For changing the port number of the Tomcat Server use the following.

Go to the services menu and then click on "Servers" and then right-click on "Apache Tomcat" and choose "Properties" as in the following:
Step 3(b)
Now select the server port number that you chose in configuring the Apache Tomcat Server. Since I chose port 9999 in Apache Tomcat so it needs to be changed in Netbeans also. As in the following:
Step 3(c)
Now click on close and run the project. For running your project right-click on the project and select "Run" as follows.
Output
The following output is generated through the specified JSP file.

Summary: This article describe how to create a JSP web page in the Netbeans IDE, hope you enjoyed doing it. If you encounter a problem creating a JSP web page or any issue occur then you can tell me.

Thanks for reading.

# data[].attributes.attachment_link.title
How to Create JSP Web Page in Netbeans IDE 7.4 Using Tomcat Server 7.0.40

# data[].attributes.attachment_link.description
In this article we discuss how to create a JSP web page in the Netbeans IDE 7.4 using the Tomcat Server 7.0.40. To create a JSP web page in the Netbeans IDE we must do the following three main steps: Start by creating a "Java web" -> "web application project".

# data[].attributes.attachment_link.readable_text
This article is an attempt to aid readers who find difficulty in creating a JDBC application in NetBeans. The idea is to keep things as simple as possible so that one can go hands-on right from the beginning. Being able to see your first application running is not only fun but also improves one's theoretical base. In computing, there are several way to do one simple thing. This step-by-step guide is just one of them. The application created is nothing fancy, of course; including the SQL statement used for DDL and DML are a bare minimum. Once the steps provided in this article are implemented, one can make one's own choices and preferences; until then, follow this article. So without further ado, let's start.

Step 0: What We Need (Rather, What We Have Used in This Article)

That's all...and oh! You also need a Linux platform. The idea is same for Windows as well, except for the Terminal command used for setting up your MySQL user account in part of Step 1.

Step 1: Setting Up Your MySQL User Account

Assuming that the MySQL database is installed properly, we'll create a user account to work with the database. It is always a good idea to use a different user account to play with the database rather than always using the default root user account.

Open Linux Terminal and start the database server by executing the command mysql, as follows. This will start the MySQL Server.
$ service mysql start or restart

Then, start the MySQL monitor to set up your user account.
$ mysql -h localhost -u root

The -h option indicates the host on which MySQL service is running. The -u option indicates a user account; root is a default user. If a root password is set (during installation), add -p (it will prompt you for a password); otherwise, leave it blank.

In the mysql> prompt, type:
USE mysql;

This will select the built-in database called mysql, which stores server information such as user accounts and their privileges.

Add a new account to the mysqlbuilt-in database with all required privileges.
create user 'mickey'@'localhost' identified by 'mickey';grant select, create, drop, references, insert, update,delete, execute on *.* to 'mickey'@'localhost';

This will create a user named mickey with password mickey.

Type the command exit; to terminate MySQL monitor

Step 2: Create the Database

The MySQL database (which we'll create down the line with the CREATE command) is like a folder where all the related tables are stored. So, in most cases, when the theme of the database changes, we keep the table that adheres to the theme encompassed within a logical area called the database. For example, a library database may contain tables such asbooks, authors, publisher, borrowing, and so forth. But, before we create the database, we must log in to MySQL with the new user we have just created (if you have not created any, use the default root user).

Log in again with the new user account. Because we have used "set password" for this user, -p will prompt for it.
mysql -h localhost -u mickey -p

Create a database. Here, testdbis like a folder, a container that will contain all the tables we will create.
CREATE testdb;USE testdb;

Now, create tables with the following SQL DDL:
create table books(isbn varchar(20) primary key,title varchar(50),edition varchar(20),price float(10,2));create table authors(author_id int primary key,author_name varchar(50));create table book_by_author(isbn varchar(20),author_id int,foreign key(isbn) references books(isbn),foreign key(author_id) references authors(author_id));

Insert some dummy data. This will help in testing the application later.

insert into books values('123456','Discrete Math','Second',56.78);insert into books values('234567','Integral Calculus','Second',92.73);insert into books values('345678','Differential Calculus','First',57.86);insert into books values('456789','Graph Theory','Second',33.8);insert into books values('567890','Set Theory','Fourth',34.89);insert into books values('102938','Numerical Methods','Third',98.46);insert into authors values(1,'CS Liu');insert into authors values(2,'N Deo');insert into authors values(3,'Rogers');insert into authors values(4,'Saxena');insert into authors values(5,'Sandip');insert into authors values(6,'Srivastava');insert into authors values(7,'Jha');insert into book_by_author values('123456',1);insert into book_by_author values('123456',2);insert into book_by_author values('123456',3);insert into book_by_author values('234567',4);insert into book_by_author values('234567',5);insert into book_by_author values('345678',6);insert into book_by_author values('456789',7);insert into book_by_author values('567890',4);insert into book_by_author values('102938',6);

Terminate MySQl monitor with the exit; command.

Up to this point, there has been nothing to do with Java; we are basically dealing with SQL DDL in MySQL Monitor. From the next step onwards, we'll deal with Java and NetBeans.

Step 3: Create a Java Project

Open the NetBeans IDE and create a Java Project in the following manner:

1. File → New Project; a window will appear. Select Java from the Categories list and Java Application from the Projects list. Click Next.

2. In the New Java Application window, enter the name location of the project. Optionally, check Use Dedicated Folder for Storing Librariesor un-check it. It does not matter, at least for our current project, but the purpose is clearly stated in the help section; let's not restate it here.

Figure 1: Assigning a project name and location

Click Finish. This will create a Java project environment in NetBeans.

Figure 2: The Java project environment is created

Step 4: Add the MySQL JDBC Driver

Because it is a JDBC project and we opt to connect to a MySQL database, we need MySQL JDBC Driver. It is basically a vendor-specific Type 4 driver that bridges the communication gap between our application and the database. If you want to connect to any other database, look for that database-specific JDBC driver. A JDBC Driver for almost all major databases (Oracle, PostgreSQL, and so on) is available in the relevant vendor sites.

Right-click the project name in the Projects tree view → Properties.

Select Libraries from the Categoriestree view.

Figure 3: Selecting Libraries from the Categories tree view

Click the Add Library button. An Add Library window will appear. If the MySQL JDBC Driver is not present in the available libraries list, click the Import...button. Then, click the MySQL JDBC Driver from the available libraries list.

Note: The MySQL JDBC Driver is already shipped with NetBeans. There is no need to install it separately. Other drivers, which may not be shipped with NetBeans, may need to be imported as a separate jar file. In such a case, use the Add JAR/Folder button to import it in the current project.

Figure 4: Adding a Library

If the import is successful, the imported jar file will be shown in the projects list.

Figure 5: The imported jar file is shown in the projects list

Now that everything is set, we can start our code in Java.

Step 5: Creating the Application

There a few thing common to Java code in implementing a JDBC application. The package that contains all the required classes and interfaces for JDBC programming is java.sql. The exceptions that may occur are handled by the object of the SQLException reference defined in the same package.

Connecting to the database
Database connection is established by creating a Connection object. The Connection is an interface and the object that implements the Connection interface manages the connection between Java and the database. A reference to the Connection object is created with the help of the overloaded method getConnection(), defined in the DriverManager class. One of the overloaded getConnection() methods takes three parameters.

Database URL of the format jdbc:mysql://hostname:portNumber/databaseName for MySQL. This format may change when connecting to other databases.

Database user name

Database password

Executing the SQL query

Processing the query result

When we put these together, it looks like this. This is the code we write inside the SimpleJDBCApplication.java source file, which basically fetches the record we have inserted in the books table we have created.

package simplejdbcapplication;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SimpleJDBCApplication {

   static final String DB_URL =
      "jdbc:mysql://localhost:3306/testdb";
   static final String DB_DRV =
      "com.mysql.jdbc.Driver";
   static final String DB_USER = "mickey";
   static final String DB_PASSWD = "mickey";

   public static void main(String[] args){

      Connection connection = null;
      Statement statement = null;
      ResultSet resultSet = null;

      try{
         connection=DriverManager.getConnection
            (DB_URL,DB_USER,DB_PASSWD);
         statement=connection.createStatement();
         resultSet=statement.executeQuery
            ("SELECT * FROM books");
         while(resultSet.next()){
            System.out.printf("%s\t%s\t%s\t%f\n",
            resultSet.getString(1),
            resultSet.getString(2),
            resultSet.getString(3),
            resultSet.getFloat(4));
         }

      }catch(SQLException ex){
      }finally{
         try {
            resultSet.close();
            statement.close();
            connection.close();
         } catch (SQLException ex) {
         }
      }
   }
}

Step 6: Execute the Application

Click Run→ Run Project, or press Ctrl+F11. This will compile and execute the project.

Conclusion

<!-bottom_orange_callout_box->

That's all you need to kick start a JDBC application in NetBeans. Now, to play with the code what you can do is implement insert, update, and delete operations.

References

Refer to the Java Documentation and have a look at the following interfaces apart from what we have used in the preceding code. They will be helpful in implementing new operations.

java.sql.ResultSetMetadata

java.sql.DatabaseMetaData

java.sql.PreparedStatement

Here are a few links to JDBC-related articles which one might find interesting.

This article was originally published on May 3, 2017

# data[].attributes.attachment_link.title
Creating a JDBC Application in NetBeans: A Step-by-Step Guide

# data[].attributes.attachment_link.description
This article is an attempt to aid readers who find difficulty in creating a JDBC application in NetBeans. The idea is to keep things as simple as possible so that one can go hands-on right from the beginning. Being able to see your first application running is not only fun but also improves one's theoretical base.

# data[].attributes.attachment_link.description
What is web-application? Learn Servlet Technology? What is Servlet Request and Response? Simple and Best Servlet Tutorial to help even beginners to learn Servlet.

# data[].attributes.attachment_link.title
Creating First Servlet Application in Netbeans IDE | Servlet Tutorial | Studytonight

# data[].attributes.attachment_link.description
Creating first Servlet application in Netbeans IDE. Netbeans IDE is good for beginners in Servlet as it is simple to implement Servlet in Netbeans IDE

# data[].attributes.attachment_link.title
JSP MySQL Eclipse JEE Development Tutorial

# data[].attributes.attachment_link.description
The tutorial explores how to use JSP MYSQL along with Eclipse JEE IDE. A simple example for JSP MySQL connection. Try it.

# data[].attributes.headline
Handling HTML form data with Java Servlet

# data[].attributes.subject
Handling HTML form data with Java Servlet

# data[].attributes.attachment_link.readable_text
Details

Last Updated on 07 August 2017 &nbsp | &nbsp Print Email

Handling form data represented in HTML page is a very common task in web development. A typical scenario is the user fills in fields of a form and submits it. The server will process the request based on the submitted data, and send response back to the client. The following picture depicts that workflow with Java servlet on the server side:

To create a form in HTML we need to use the following tags:

<form>: to create a form to add fields in its body.

<input>, <select>, <textarea>...: to create form fields like text boxes, dropdown list, text area, check boxes, radio buttons,... and submit button.

To make the form works with Java servlet, we need to specify the following attributes for the <form> tag:

method="post": to send the form data as an HTTP POST request to the server. Generally, form submission should be done in HTTP POST method.

action="URL of the servlet": specifies relative URL of the servlet which is responsible for handling data posted from this form.

For example, following is HTML code of a login form:
<form name="loginForm" method="post" action="loginServlet">
	Username: <input type="text" name="username"/> <br/>
	Password: <input type="password" name="password"/> <br/>
	<input type="submit" value="Login" />
</form>

This form would look like this in browser:

On the server side, we need to create a Java servlet which is mapped to the URL: loginServlet, as specified in the form's action attribute. Following is code of the servlet:

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// code to process the form...

	}

}

Notice that the servlet's URL is specified by the @WebServlet annotation before the servlet class. When the user submits the login form above, the servlet's doPost() method will be invoked by the servlet container. Typically we will do the following tasks inside doPost() method:

Read values of the fields posted from the form via the request object (implementation of javax.servlet.http.HttpServletRequest interface).

Do some processing, e.g. connecting to database to validate the username and password.

Return response back to the user via the respone object (implementation of javax.servlet.http.HttpServletResponse interface).

To read values of form's fields, the HttpServletRequest interface provides the following methods:

String getParameter(String name) : gets value of a field which is specified by the given name, as a String. The method returns null if there is no form field exists with the given name.

String[] getParameterValues(String name) : gets values of a group of fields which have same name, in an array of String objects. The method returns null if there is no field exists with the given name.

Note that the above methods can also deal with parameters in URL's query string, hence the name getParameter. For example, we can write the following code in the doPost() method to read values of form's fields:
String username = request.getParameter("username");
String password = request.getParameter("password");

To send response back to the client, we need to obtain a writer from the response object by calling the method getWriter() of the HttpServletResponse interface:

PrintWriter writer = response.getWriter();

Then use the print() or println() method to deliver the response (in form of HTML code). For example:

String htmlRespone = "<html>";
htmlRespone += "<h2>Your username is: " + username + "</h2>";
htmlRespone += "</html>";

writer.println(htmlRespone);

Here's complete code of the servlet class to process the login form:

package net.codejava.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		// read form fields
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		System.out.println("username: " + username);
		System.out.println("password: " + password);

		// do some processing here...

		// get response writer
		PrintWriter writer = response.getWriter();

		// build HTML code
		String htmlRespone = "<html>";
		htmlRespone += "<h2>Your username is: " + username + "<br/>";
		htmlRespone += "Your password is: " + password + "</h2>";
		htmlRespone += "</html>";

		// return response
		writer.println(htmlRespone);

	}

}

Here's an example output when submitting the above login form in browser:

So far you have got the ins and outs when handling HTML form data with Java servlet. For your reference, we provide a list of examples for handling common HTML form fields as below. Note that we use the System.out.println() statement in servlet to demo the output.

username is: admin
password is: nimda

HTML code:

Speaking language:
<input type="checkbox" name="language" value="english" />English
<input type="checkbox" name="language" value="french" />French

Field image:

Java code in servlet:

String languages[] = request.getParameterValues("language");

if (languages != null) {
	System.out.println("Languages are: ");
	for (String lang : languages) {
		System.out.println("\t" + lang);
	}
}

Output:
Languages are:
	english
	french

Gender is: male

Feed back is: This tutorial is very helpful. Thanks a lot!

Job category is: science

To create a form to upload file, we need to specify the enctypeattribute for the <form> tag as follow:

<form method="post" action="uploadServlet" enctype="multipart/form-data">

		Select file to upload: <input type="file" name="uploadFile" />

		<input type="submit" value="Upload" />
</form>

For handling file upload on the server side with Java servlet, we recommend these tutorials: For the examples in this tutorial, you can download Eclipse-based project as well as deployable WAR file under the attachments section.

Add comment

# data[].attributes.attachment_link.title
Handling HTML form data with Java Servlet

# data[].attributes.attachment_link.description
Details Last Updated on 07 August 2017 &nbsp | &nbsp Print Email Handling form data represented in HTML page is a very common task in web development. A typical scenario is the user fills in fields of a form and submits it.

# data[].attributes.attachment_link.description
Servlet Home Servlet Introduction Life cycle of servlets Web.xml in Servlets Execute the Servlets Servlet Program Http Servlet Generate a War File ServletConfig Obtaining ServletConfig Object ServletContext Obtain ServletContext Object Handling Form Data Handling HTML data in Servlet Validation of a form Servlet Chaining Attribute scopes ServletContext scope Session Management Cookies HTTP Session Hidden Flow Fields

# data[].attributes.attachment_link.readable_text
After going through the introduction and architecture of servlets, let us write a simple Login Validation program. As you have seen in the architecture, there will be two programs - one running on client machine and the other on server.

Servlet Example explained in 10 steps

First let us write the client-side program.
I. Client Program - UserPass.html

localhost: It is the system where Tomcat server is running. Here, localhost is treated as the server. In realtime, actual name of server comes.

8888: It is the port number on which Tomcat is running.

india: It is the name of the folder you created and placed in web-app folder.

roses: It is the alias name of the Validation servlet given web.xml file.

Above steps are clearly explained in Step-by-Step Execution of Servlet in Tomcat.
II. Servlet program - Validation.java
Being the first Servlet Example, let us have a detailed discussion on each line.
1. import javax.servlet.*;

The above package is imported for the sake of class ServletException.
2. import javax.servlet.http.*;

The above package is imported for the abstract class
HttpServlet and interfaces HttpServletRequest and HttpServletResponse.
3. import java.io.*;

java.io package is needed for PrintWriter and IOException.
4. public class Validation extends HttpServlet
To write a servlet, it is required to extend the abstract class HttpServlet, like Applet is required to extend to write an applet.

Let us see the hierarchy of HttpServlet.

From the above hierarchy, it can be understood that to develop a servlet there are three styles.

a) by implementing Servlet interface
b) by extending GenericServlet
c) by extending HttpServlet

The disadvantage of first style is, it is required to override all the abstract methods of the interface Servlet eventhough we are not interested (like the interface WindowListener to close a frame) in a few. The better approach is extending GenericServlet (like WindowAdapter to close the frame) which contains only one abstract method service(). It is enough to the programmer to override only this method. It is a callback method. GenericServlet was used by the programmers when HTTP protocol was not standardized for the Web. When the HTTP became a defacto standard for Web, HttpServlet was designed to suit more for HTTP protocol. HttpServlet is an abstact class but without any abstract methods (all are non-abstract methods). Even the service() method is non-abstract and infact with HttpServlet, the service() method can be replaced by the methods doGet() or doPost(). This we will see later.

The above code works fine even if GenericServlet is extended instead of HttpServlet.

5. public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

service() method is a callback method called automatically when the container loads the servlet for execution when the client request comes. The method takes two parameters - an object of interface HttpServletRequest and an object of interface HttpServletResponse and let us see what these interfaces meant to servlet.
a) HttpServletRequest interface
Following is the hierarchy.

The first parameter can be either of ServletRequest or its sub-interface HttpServletRequest. We use ServletRequest as parameter when we extend GenericServlet and HttpServletRequest when HttpServlet is extended. The data send by the client (through HTML) finally reaches HttpServletRequest object after travelling intermittent stages. That is, req object of HttpServletRequest receives data sent by client. From this object, the servlet programmer can extract the data and can use for validation or other purposes as hereunder.
b) HttpServletResponse interface
The second parameter can be either of ServletResponse or its sub-interface HttpServletResponse. We use ServletResponse as parameter when we extend GenericServlet and HttpServletResponse when HttpServlet is extended. The responsibility of the data to be sent (like valid or invalid etc.) to the client is taken care by HttpServletResponse. The programmer job is simply to pass the response messages (to be reached to client) to HttpServletResponse and actual sending is taken care by the container.

c) The service() method throws two checked exceptions of javax.servlet.ServletException and java.io.IOException.
6. res.setContentType("text/html");
setContentType(String) is a method of ServletResponse inherited by HttpServletResponse and its job is sending the information to client's browser of how the response sent by the servlet is to be formatted. It is here is text or HTML. That is, the data sent to the client is either in text format (as in ("VALID")) or HTML format (as in (<b>INVALID</b>)). The difference is HTML <b> tag. This is more called as setting the MIME (Multipurpose Internet Mail Extension) type. The other types can be of image/gif etc. which we use later.

7. PrintWriter out = res.getWriter();
8. out.println("VALID");

We know earlier the HttpServletResponse is meant to send data (known as response) to client. Being an interface, it cannot be used directly. As a convenience, the getWriter() method of ServletResponse (inherited by HttpServletResponse) returns an object of PrintWriter. println() is a method of PrintWriter used to attach a message, here, as a string parameter. This string message (here, VALID OR INVALID) is ultimately sent to client by the HttpServletResponse.
9. String str1 = req.getParameter("t1");
We know the data sent by client (known as request) finally reaches HttpServletRequest. getParameter(String) method of ServletRequest (inherited by HttpServletRequest) takes a string parameter and returns a string. The parameter is nothing but the <FORM> field name (here, t1) and the returned string value is what user entered in field t1. Using getParameter() method, the programmer extracts all the data sent by the client. The other way is getParameterNames() where all the data is extracted in a single stretch in a for loop.
10. out.close();
When the job is over, it is customary to close the streams as you have done in file copying.

Pass your comments to improve the tutorial First "Servlet Example Login Screen Validation".

# data[].attributes.attachment_link.title
First Servlet Example Login Screen Validation

# data[].attributes.attachment_link.description
After going through the introduction and architecture of servlets, let us write a simple Login Validation program. As you have seen in the architecture, there will be two programs - one running on client machine and the other on server. Servlet Example explained in 10 steps First let us write the client-side program.

# data[].attributes.headline
Request attributes in servlet with an example ( Attribute scope )

# data[].attributes.subject
Request attributes in servlet with an example ( Attribute scope )

# data[].attributes.attachment_link.readable_text
A Servlet can communicate with another servlet or JSP by using RequestDispatcher object (which is commonly known as servlet chaining). To pass additional information between source and destination servlets , we can use request attributes .

String) and value ( Request attributes are the name (Object) pairs.

In servlet chaining , If we create request attribute in the source servlet (Ex : SetAttributeServlet) , it can be visible and accessible in the destination servlet/JSP (Ex : GetAttributeServlet).

If any servlet (Ex: IndividualTestServlet) not participate in the servlet chaining , it cannot access request attributes even though it resides in the same web application.

Request attribute allocates memory in the ServletRequest object.

Request attributes are specific to each and every request (request scope).

Create request attributes :

request.setAttribute("name","java2db");

Attribute value must be an object . But we passed a String value , so it applies auto boxing .

Modify request attributes :

request.setAttribute("name","java2db.com");

Remove request attributes :

<HttpServletRequest_Obj> . removeAttribute("<Attribute_Name>") ;

request.removeAttribute("name","java2db.com");

Access request attributes :

(Type)<HttpServletRequest_Obj> . getAttribute("<Attribute_Name>") ;

String name = (String)request.getAttribute("name");

Complete example for request attributes :

Execution result :

http://localhost:8080/RequestAttributes/index.jsp

Change the IP address and Port according to your server location IP and Port.

Enter the details and click Submit button.

The response will be the below window.

Now test the individual servlet which is not participating in the servlet chaining with it's (http://localhost:8080/RequestAttributes/indServlet) URL . The response comes with null values (Because there is no call from any servlet with RequestDispatcher object).

# data[].attributes.attachment_link.title
Request attributes in servlet with an example (Attribute scope)

# data[].attributes.attachment_link.description
A Servlet can communicate with another servlet or JSP by using RequestDispatcher object (which is commonly known as servlet chaining). To pass additional information between source and destination servlets , we can use request attributes . String) and value ( Request attributes are the name (Object) pairs.

# data[].attributes.attachment_link.title
Deploying and Configuring Web Applications