Servlet, Html & Database question.


I have  a question regarding a web application using Database.
I want to create a webapplication using HTML & servlets. Whenever the user enters the id on the web application. It should validate with the Database tables which I have already created. And if the id  of the user is correct then the other information entered by the user should be stored in the database.
How to write the code to do all these features?
Kindly help.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can certainly do that if you  be more clear.

In your table in the database do you have the table with just the user Id and all other columns being null?If so

Format will go like this
1>Get the Ids and store it in a bean
2>Create a jsp and use the bean in the JSP
3>When ever user enters a id check that with the values in the bean
4>If it is successfult then run a update query on the database using JDBC

We would be able to help you more if you clearly explain what how your design is?
Hi deepamyler,

Have you prepared all the environment ready? I mean that do you set everything for JSP/HTML - Servlet - Database ready? And the Servlet can connect to database already.

If so, you can easily get the id from the user's input....normally from getParameter() in your Servlet. Then you need to query your database whether this value is or is NOT in the database. If yes, you may redirect him or her to success.html otherwise bad.html.

Please let me know if you need any help.

Here's a load of code from an earlier question that I answered. Most of it would be applicable to your situation.

All the points made above are valid, you need to post a lot more information as regards to your db schema, table names, how your servlet container is configured etc, and the general advice with regards to the flow of the application is good. You should use a form to get the username and password to send to a jsp or servlet which then does the authentication. code // our javabean
package com.bloodredsun.beans ;
import java.sql.*;

public class Connectionbean{

private Connection conn ;
private Statement stmt ;
private static final String driver = "" ; // your db driver
private static final String dbURL= "" ; //your db url
private static final String login= "" ; // your db login
private static final String password= "" ; //your db password

  public ConnectionBean(){
      Class.forName( driver ) ;
      conn = DriverManager.getConnection(dbURL, login, password);
      stmt = conn.createStatement() ;

    }catch (Exception e){
      System.out.print("Whoops, buggered") ;
  }//end ConnectionBbean constructor

      public ResultSet executeQuery ( String pSql){
      return stmt.executeQuery( pSql ) ;

Database.jsp code
<%@ page import="java.sql.*, com.bloodredsun.beans.*" %>
<jsp:useBean id="beanconnection" class="ConnectionBean" scope="request"/>
String sql = "Select * from myTable" ;
ResultSet rs = beanconnection.executeQuery( sql) ;
<%-- We now have the ResultSet, do what you will --%>
while ( ){
A line of db stuff <%= rs.getString("id") %>


This is bare-arsed stuff, you will have to complete it with the normal extra methods in the bean for closing the connection, and other things like that and therer is minimal exception handling (in fact I've not tested this but written it straight out, but the theory is sound). What you can see is that Javabeans allow you to COMPONENTIZE code in that the code required for creating the db connection and statement were put in the JavaBean. This can then be dropped in as many pages as you like with out the need for repeatedly setting up the connection.

Once you have got used to JavaBeans in your JSP, I would recommend then doing it in a servlet. Then, once you've done that, have a look at custom tags and you'll see why JSTL is so popular (JSTL just being a set of standardised custom tags).

My next advice would be to look at dataSources and connection pools, this has a huge performance benefit for larger projects and also takes you into the world of JNDI (which isn't a frightening as it seems!).

Good luck and happy coding.

Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

deepamylerAuthor Commented:

I have created the servlet for the validation of the user info. After the validation the user is taken to the main information page in which there are several links to the various online forms. Based upon the link the user clicks he will be taken to appropriate servlet or jsp page. If he has filled the form once he will not be allowed to  fill the form again but given the summary of the form information( a JSP page) he had filled in.
My question is if I  want to use href for the links instead of radio buttons  how will I know the name - value of the link selected to proceed further.
I don't want to use radio buttons for the links.

>>My question is if I  want to use href for the links instead of radio buttons  how will I know the name - value of the link selected to proceed further.

Use request parameters for the links. You can have as many as you like and there are always "name" and "value", joined with an equals sign (=)

<a href="">Go to index</a>
<a href="">Go to personal</a>
<a href="">Go to checkout</a>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glad to have helped..
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.