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 5971901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:34:56+00:00 2026-05-22T20:34:56+00:00

I have a JSP file Signup.jsp which submits to UserDetails servlet which inserts the

  • 0

I have a JSP file Signup.jsp which submits to UserDetails servlet which inserts the user details in the database “tblusers” and forwards to ElecBill.jsp after successful data insertion. Instead of forwards to ElecBill.jsp it is forwarding to Signup.jsp. In other words, insertion of data has failed.

Here is the servlet code:

package com.elecbill;

import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;


public class UserDetails extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws javax.servlet.ServletException, IOException
{

String userid=request.getParameter("uid");
String firstname=request.getParameter("fname");
String lastname=request.getParameter("lname");
String phonenum=request.getParameter("phone");
String mobilenum=request.getParameter("mobile");
String email=request.getParameter("email");
String login=request.getParameter("loginid");
String pass=request.getParameter("pass");
String pass1=request.getParameter("pass1");
try
{

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/elecbill","root","root");    
String query="insert into tblusers('"+userid+"','"+firstname+"','"+lastname+"','"+phonenum+"','"+mobilenum+"','"+email+"','"+login+"','"+pass+"','"+pass1+"')";

Statement s=conn.createStatement();
ResultSet rs=s.executeQuery("select * from tblusers");
boolean str=false;
while(rs.next())
{
    if((rs.getString(6).equals(login)))
    {
        str=true;
    }
}
   if(!str)
{
    s.executeUpdate(query);
    HttpSession ses=request.getSession(true);
    ses.setAttribute("login",login);
    RequestDispatcher rq=request.getRequestDispatcher("ElecBill.jsp");
    request.setAttribute("msg","Registered Successfully");
    rq.forward(request,response);
    System.out.println("Successfully");

}
  else
{
 RequestDispatcher rq=request.getRequestDispatcher("signup.jsp");
 request.setAttribute("msg","Im Already in use. Choose another Id");
 rq.forward(request,response);


}

  }
  catch (Exception e)
  {
e.printStackTrace();
  }

 }

}

How is this problem caused and how can I solve it?

  • 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-05-22T20:34:57+00:00Added an answer on May 22, 2026 at 8:34 pm

    The insertion of the data hasn’t failed. Even more, according to the code flow it isn’t been executed at all. According to your code flow, it just means that the user-supplied loginid parameter has a match with the value of the 6th column of one of the table rows.

    Try supplying a different loginid value.


    Unrelated to the concrete problem, this piece of code is sensitive to SQL injection attacks. Use PreparedStatement. Also, finding an existing login ID is in this piece of code very inefficient as you’re copying the entire DB table into Java’s memory and doing the comparison in Java instead of in SQL. Learn how to use the WHERE clause and just use boolean exist = resultSet.next().

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

Sidebar

Related Questions

let's say i have a servlet that forwards a request to a jsp file
I have a JSP file which creates an Excel document. I want to dynamically
I have a form in a jsp file, which I have used to get
I have a jsp file which contain javascript functions at top of file. These
I have created a child.jsp file which has a button named Continue. I have
I have a JSP file in which I have an entity class - I
Hi i am using apache tomcat. i have a jsp file for entering user
I get the strangest thing going on... I have a JSP file which read
I have a jsp file that generates some files at runtime, which are also
i have a JSP file in which i have declared a method which return

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.