Results 1 to 5 of 5
  1. #1
    sanser is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Question How to insert drop down values( using servlet from html ) into back end

    Hi Everybody,

    I created a html page including the drop down column and trying to connect the database using Servlets and trying to insert the values to my database(oracle).
    I am able to connect to back end and able to insert all the values except drop down values.
    Please can any one help me how to insert the drop down values into data base using Servlets....Thank you in advance.....


    Thanks..

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What happens when you try to insert the database values? Are the values getting to the servlet?

  3. #3
    sanser is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default Thanks for ur response

    Thanks for your response r035198x,

    In my table am seeing all the values except one column i.e, Dropdown value.
    My html page is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> User Personal Information </TITLE>

    </HEAD>

    <BODY>
    <BODY bgcolor="orange">WELCOME TO OUR SITE<br><br><br>
    Please Fill The Bellow Form:
    <form method="post" action="/mini/servlet/Qinfo">


    <table border="1" align="center"><br><br>
    First Name<input type="text" name="Fname" ></br></br>
    Last Name<input type="text" name="Lname" ></br></br>
    SSN <input type="text" name="ssn"></br></br>
    Gross Monthly income<input type="text" name="GMonthlyIncome"></br></br>
    Net Monthly Income<input type="text" name="NMonthlyIncome"></br></br>
    Indicator: <select value="Indicator">
    <option>1</option>
    <option>2</option>
    </select ></br></br></br>
    <input type="submit" value="submit"></br></br>

    </BODY>
    </HTML>
    and servlet is:
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Qinfo extends HttpServlet
    {

    private ServletConfig config;
    public void init(ServletConfig config)
    throws ServletException{
    this.config=config;
    }
    public void doPost(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
    {
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    Connection con=null;
    ResultSet rs;
    String Fname=req.getParameter("Fname");
    String Lname=req.getParameter("Lname");
    String ssn=req.getParameter("ssn");
    String GMincome=req.getParameter("GMonthlyIncome");
    String NMincome=req.getParameter("NMonthlyIncome");
    String Indicator=req.getParameter("Indicator");
    out.println("<html><body bgcolor=orange>");
    if(Fname==null||Fname.equals("")){
    out.println(" <br>please enter the First name");}

    if(Lname==null||Lname.equals("")){
    out.println("<br>please enter the Last Name");}


    if(ssn==null||ssn.equals("")) {
    out.println("<br>Please enter the 9 digit ssn");}
    if(GMincome==null||GMincome.equals("")) {
    out.println("<br>Please enter the Gross Monthly Income");}
    if(NMincome==null||NMincome.equals("")) {
    out.println("<br>Please enter the Net Monthly Income");}
    else
    {
    out.println("<br>WELCOME:"+Fname);

    out.println("</body></html>");
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con=DriverManager.getConnection("jdbc: oracle:thin:@192.168.0.***:1521: DBname","scott","scott");
    PreparedStatement stmt=con.prepareStatement("insert into qinfo values(?,?,?,?,?,?)");
    stmt.setString(1,Fname);
    stmt.setString(2,Lname);
    stmt.setString(3,ssn);
    stmt.setString(4,GMincome);
    stmt.setString(5,NMincome);
    stmt.setString(6,Indicator);
    stmt.executeUpdate();
    con.close();
    out.println("<br><h4> Thank you for the information<br>");
    }
    catch(Exception e)
    {
    res.sendError(500,e.toString());
    }
    }
    }}

    Please can you check my program and please let me know if i did anything wrong.Thank you.
    Last edited by sanser; 10-19-2009 at 11:41 PM. Reason: easy to read

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    1.) Use JSPs for presentation if possible. Don't try to write html code in servlets.
    2.) Where is your closing form tag?
    3.) Give your select a name attribute not a value and give your options value attributes.
    4.) Close connections in a finally block.

  5. #5
    sanser is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default Thank you r035198x

    Thanks r035198x,
    Now its working.Thanks for your help.

Similar Threads

  1. Replies: 2
    Last Post: 10-07-2009, 07:24 PM
  2. Replies: 1
    Last Post: 08-05-2009, 03:43 AM
  3. INSERT INTO Forum VALUES (Mysystem,new)
    By mysystem in forum Introductions
    Replies: 1
    Last Post: 07-31-2009, 11:49 PM
  4. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 05:06 PM
  5. Getting HTML form values in Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-17-2007, 09:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •