Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8855277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:05:56+00:00 2026-06-14T14:05:56+00:00

Hi all when I run my servlet which contains a form and click submit

  • 0

Hi all when I run my servlet which contains a form and click submit I get the following error, I cannot find the error in my code but there is obviously one. Otherwise when I click submit the following appears in the Eclipse console:

ss
ss
zz@z.com
56464
asdcity
pen
null
22
Done1
Failed

There are two problems in here. First, null value is retrieved for payment mode. Second, insertions in database fails.

Form :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form</title>
</head>
<body>
<form action="SaveServlet">
    First Name: <input type="text" name="firstname"><br>
    Last Name:<input type="text" name="lastname"><br>
    Email ID:<input type="text" name="email_id"><br>
    Phone number:<input type="text" name="phone_number"><br>
    Address:<input type="text" name="address"><br>
    Purchasing Item:<input type="text" name="purchasing_item"><br>
    Payment Mode: <select name="paymentment_mode">
<option>Visa</option>
<option>Master</option>
<option>Mastro</option>
<option>Amex</option>
</select><br>
    Card number:<input type="text" name="card_number"><br>
<input type="submit" value="Save"></input>
</form>
</body>
</html>

Servlet :

package myPack;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class SaveServlet
*/
public class SaveServlet extends HttpServlet
{
    private static final long serialVersionUID = 1L;

    /**
     * Default constructor.
     */
    public SaveServlet() {
        // TODO Auto-generated constructor stub
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws        ServletException, IOException {

        String s1=request.getParameter("firstname");
        System.out.println(s1);

        String s2=request.getParameter("lastname");
        System.out.println(s2);

        String s3=request.getParameter("email_id");
        System.out.println(s3);

        String s4=request.getParameter("phone_number");
        int s41=Integer.parseInt(s4);
        System.out.println(s41);

        String s5=request.getParameter("address");
        System.out.println(s5);

        String s6=request.getParameter("purchasing_item");
        System.out.println(s6);

        String s7=request.getParameter("payment_mode");
        System.out.println(s7);

        String s8=request.getParameter("card_number");
        int s81=Integer.parseInt(s8);
        System.out.println(s8);

        String c="jdbc:mysql://localhost:3306/test";
        System.out.println("Done1");


        Connection con=null;

        try{

            Class.forName("com.mysql.jdbc.Driver").newInstance();
            System.out.println("Done2");

            con = DriverManager.getConnection(c, "root", "MyNewPass");
            System.out.println("Done3");

            PreparedStatement ps=null;
            System.out.println("Done4");

            String qs = "insert into table1 values(?,?,?,?,?,?,?,?);";
            ps = con.prepareStatement(qs);
            ps.setString(1,s1);
            ps.setString(2,s2);
            ps.setString(3,s3);
            ps.setInt(4,s41);
            ps.setString(5,s5);
            ps.setString(6,s6);
            ps.setString(7,s7);
            ps.setInt(8,s81);
            System.out.println("Success");
            ps.execute();
            con.close();

        }
        catch (Exception e) {
        // TODO: handle exception
            System.out.println("Failed");}}
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws     ServletException, IOException {
        // TODO Auto-generated method stub
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:05:57+00:00Added an answer on June 14, 2026 at 2:05 pm

    It looks like it is breaking at the Class.forName("com.mysql.jdbc.Driver").newInstance(); line. Make sure you have included the MySQL JDBC jar file inside your WEB-INF/lib directory.

    Here is a link you can download the right version :

    http://dev.mysql.com/downloads/connector/j/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi all when I run my servlet which contains a form and click submit
We all run into errors using Drupal-- most of which are easy to fix.
when calling PQconnectdb in the main program all run very well, but if i
I want run all script from the directory . Like , The directory contains
So this all began in trying to get Coldfusion9 portlets to run under Liferay,
I been working on this Servlet project all morning and now suddenly I cannot
We have a large system of physical devices which all run a web service
I am creating a Java service which will run within a web servlet container
We have a servlet project, which contains (among many other classes) an interface that
How can I start a thread which will run in the background but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.