Servlet, Html & Database question.

Hi,

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.

Thanks.
deepamylerAsked:
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.

koppchaCommented:
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?
0
suprapto45Commented:
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.

Regards
Dave
0
bloodredsunCommented:
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.

ConnectionBean.java code // our javabean
<code>
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(){
    try{
      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 ) ;
      }
}//end ConnectionBean.java
</code>

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

<%
}
%>
</body>
</html>
</code>

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.

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

deepamylerAuthor Commented:
Hi,

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.

Thanks.
0
bloodredsunCommented:
>>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 (=)
e.g.

<a href="servlet.do?page=index.jsp&userId=1234">Go to index</a>
<a href="servlet.do?page=personal.jsp&userId=1234">Go to personal</a>
<a href="servlet.do?page=checkout.jsp&userId=1234">Go to checkout</a>
0

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
bloodredsunCommented:
Glad to have helped..
0
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
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.