How to transfer data from JSP to servlet when submitting HTML form

send data from jsp to servlet without form
how to send request from jsp to servlet
how to retrieve data from database using servlet and display in html form
how to send response from servlet to html page
how to add html code in servlet
how to pass object from jsp to servlet
how to pass value from one form to another in jsp
how to send table data from jsp to servlet

I have a JSP page with an HTML form:

<form action="SERVLET">
    <input type="text" name="name"/><br>        
    <input type="text" name="group"/>
    <input type="text" name="pass"/>
    <input type="submit" value="submit">            

How to obtain these data in a servlet and add them to database?

Passing Data from JSP to Servlet, Alternatively, you can pass data between a JSP page and a servlet through an of the searchCond request parameter input by the user through the HTML form. This servlet form example shows you how to create HTML or JSP form and send form data to the servlet. In this tutorial I have followed servlet 3 annotations based, so please make sure you have servlet 3.1 jar.

Well, there are plenty of database tutorials online for java (what you're looking for is called JDBC). But if you are using plain servlets, you will have a class that extends HttpServlet and inside it you will have two methods that look like

public void doPost(HttpServletRequest req, HttpServletResponse resp){



public void doGet(HttpServletRequest req, HttpServletResponse resp){


One of them is called to handle GET operations and another is used to handle POST operations. You will then use the HttpServletRequest object to get the parameters that were passed as part of the form like so:

String name = req.getParameter("name");

Then, once you have the data from the form, it's relatively easy to add it to a database using a JDBC tutorial that is widely available on the web. I also suggest searching for a basic Java servlet tutorial to get you started. It's very easy, although there are a number of steps that need to be configured correctly.

How to handle HTML form data with Java Servlet, Passing Data to a Servlet Invoked from a JSP Page or application-relative path of the target JSP page as input to the getRequestDispatcher() method:. Banchan Sangma wrote:you see, im entering the form details on a jsp, and i want to use a bean to transfer that data from jsp to a servlet. That is not possible. JSP is just a server-side templating engine -- what is sent to the browser is the resulting HTML. Please read this article to understand what JSP is and how it works.

Search for :


You want to process the data from an HTML form in a servlet. "

JSP-Servlet Interaction, This servlet form example shows you how to send form data to servlet either from html or from jsp form, Try this with latest servlet 3 version  When you ultimately need to forward to a JSP in a servlet, you should generally keep your fingers off from the response object in the servlet as it's then the JSP who will handle the response. – BalusC Oct 1 '13 at 18:51

first up on create your jsp file : and write the text field which you want for ex:

after that create your servlet class:

public class test{

protected void doGet(paramter , paramter){

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


JSP-Servlet Interaction, The browser uses two methods to pass this information to the web server. JSP handles form data parsing automatically using the following methods is an example that passes two values using the HTML FORM and the submit button. 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. 1.

Servlet form example, I am trying to pass values from JSP Page to Servlets but I am getting a NullPointerException <html>. <head>. <title>Student Registration Form</title>. <style type= "text/css" > <input type= "submit" value= "Submit" >. action: this attribute specifies the relative url of the servlet which handles the form submission, in our example, we should have defined a servlet mapped by “/LoginProcessor” in our application. method: this attribute defines the submit method, there are 2 ways of passing form data from client side to server side:

JSP - Form Processing, JSP primarily contains tags like HTML. Servlets, are server side java programs. Servlets are mainly used as a controller to transfer a data from JSP form to  HTML form basically is a graphic user interface (GUI) which you present to get the input data from users. Once users submit the form from the client side, on the server side, you need to capture those data for further processing such as business logic validation, saving the data into the database and so on.

JSP Tutorial #29 - Read HTML Form Data with Servlets, This message comes to the backend program in the form of the standard input which you can parse and use for your processing. Servlet handles this type of requests using doPost() method. Reading Form Data using Servlet. Servlets handles form data parsing automatically using the following methods depending on the situation −