Results 1 to 10 of 10
Like Tree2Likes
  • 1 Post By gimbal2
  • 1 Post By SurfMan

Thread: dynamically related combobox in jsp issue

  1. #1
    ppreeti is offline Member
    Join Date
    Mar 2014
    Posts
    17
    Rep Power
    0

    Default dynamically related combobox in jsp issue

    Hi !
    I am new to JSP. I want 2 create 2 dynamic related combobox that pull values from database. I took the help from this link:
    dynamically populate the city combo box based on the values of state combo +ajax+jsp.
    It runs fine but if there are special characters in the table it doesn't display the list at all. So thats my problem no. 1.

    Secondly, I want to add a submit button so that a relevant page can be fetched accordingly. The related combobox will be used for search functionality.
    Kindly help me to implement the same.
    Thanks !

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,855
    Rep Power
    5

    Default Re: dynamically related combobox in jsp issue

    The first one probably requires you to look into character encoding. The second one is not a problem description of any kind - you need to sit down and go do your job. If you can't do that, you need to study more. I suggest you give this free online book a read:

    Free Online Version of Core Servlets and JavaServer Pages (Second Edition) in PDF
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    ppreeti is offline Member
    Join Date
    Mar 2014
    Posts
    17
    Rep Power
    0

    Default Re: dynamically related combobox in jsp issue

    Kindly modify the same code in the link that handles the issue of character encoding. Also help me to implement the search functionality with a submit button that searches on the basis of values in the combobox.
    ( Kindly do it in the same code) I need to do this urgently. I'll be really glad if you help me. Thanks !

  4. #4
    ppreeti is offline Member
    Join Date
    Mar 2014
    Posts
    17
    Rep Power
    0

    Default Re: dynamically related combobox in jsp issue

    Thank you for the link. I'll definitely have a look at that. But please help me achieve the same (modifying the same code). I need urgent help regarding the same.
    Thanks !

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,855
    Rep Power
    5

    Default Re: dynamically related combobox in jsp issue

    Sorry, I'm not kindly. I'm a real mean person who demands that people do things themselves.

    But if you have code that you want help with and you have specific questions about, my icy outer layer melts and I become more kindly.
    SurfMan likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: dynamically related combobox in jsp issue

    Quote Originally Posted by gimbal2 View Post
    Sorry, I'm not kindly. I'm a real mean person who demands that people do things themselves.
    You heartless bastard! How can you expect people to do that? He asked kindly! Tsssk, so you're not handing out teh free codez in teh jav?
    gimbal2 likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #7
    ppreeti is offline Member
    Join Date
    Mar 2014
    Posts
    17
    Rep Power
    0

    Default Re: dynamically related combobox in jsp issue

    Even I believe in the same ideology but its just that I've meddled and googled a lot and still cudn't find the answer .Hence, I need your support which is urgent. Please..please help me to solve this ! I'll be more than obliged for that !
    1. Please fix the special character issue (as I already mentioned)
    2.make a search button that searches database based on the value in 2 combobox.
    here is my code:-



    (PLEASE MAKE THE NECESSARY MODIFICATIONS IN THIS CODE ONLY !)
    search_city.jsp
    -------------
    <%@page import = "java.io.PrintWriter" %>
    <%@page import="java.sql.*"%>
    <%@page import="cb.*"%>

    <html>
    <head>

    <script type="text/javascript">
    function showcity(str)
    {
    //document.forms[0].action="getcustomer.jsp?q="+str;
    //document.forms[0].submit();
    document.getElementById("cities").length = 0;


    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","getcity.jsp?q="+str,true);
    xmlhttp.onreadystatechange=function()
    {


    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {

    var xml=xmlhttp.responseXML;

    var tags=xml.getElementsByTagName("tr");
    for(var i=0;i<tags.length;i++)
    {
    var combo = document.getElementById("cities");
    var option = document.createElement("option");
    option.text = tags[i].childNodes[0].childNodes[0].nodeValue;
    option.value = tags[i].childNodes[0].childNodes[0].nodeValue;
    try
    {
    combo.add(option, null); //Standard
    }catch(error){combo.add(option); // IE only
    }


    }
    //document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
    //document.getElementById("names").value =xmlhttp.responseText;
    }
    }
    xmlhttp.send();

    }
    </script>
    </head>
    <body>

    <form name="form1" action="" method="post">

    <table width="800" border="1">
    <tr>
    <td>State Name </td>
    <td> <%

    //String tables = "<table><tr><td>hiii</td></tr></table>";
    //out.print(names);
    try{
    state s = new state();
    ResultSet rs= s.getStates();
    String ss;

    %>
    <select id="combos" name="combos" onChange="showcity(this.value)">
    <%
    while(rs.next())
    {
    ss= rs.getString(2);
    %>
    <option value= "<%= ss %>" ><%=ss %></option>
    <%
    }
    %>
    </select>

    <%
    }
    catch(Exception e){}
    %>
    </td>
    </tr>
    <tr>
    <td>City</td>
    <td><select id="cities" name="cities" ></td>
    </tr>
    </table>

    </form>
    </body>
    </html>



    getcity.jsp
    --------------
    <%@page import = "java.io.PrintWriter" %>
    <%@page import="java.sql.*"%>
    <%@page import="cb.city"%>
    <%
    String names = request.getParameter("q");
    out.print(names);
    try{
    city c= new city();
    ResultSet rs= c.getCity(names);
    String xml="<table>";
    while(rs.next()){
    xml+="<tr>";
    xml+="<td>";
    xml+=rs.getString(1);
    xml+="</td>";
    xml+="</tr>";
    }
    xml+="</table>";
    out.print(xml);
    //con.close();
    PrintWriter pw=response.getWriter();
    response.setContentType("text/xml");
    pw.write(xml);
    pw.flush();
    pw.close();


    /* String buffer="<select name='state' onchange='showCity(this.value);'><option value='-1'>Select</option>";
    while(rs.next()){

    buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";

    }
    buffer=buffer+"</select>";

    response.getWriter().println(buffer);
    */

    }
    catch(Exception e){}

    %>


    city.java
    ---------
    package cb;

    import java.sql.*;
    public class city extends connection {
    public ResultSet getCity(String Statename)
    {
    ResultSet rs = null;

    try{
    get_connection();

    System.out.println("coming here");

    /*rs= st.executeQuery("select city.city_name as cname from city,state where city.state_id=state.state_id and state.state_name= '"+ Statename+"'" );*/
    rs= st.executeQuery("select entry.entry_name as cname from entry,index1 where entry.index_id=index1.index_id and index1.index_name= '"+ Statename+"'" );


    /*rs= st.executeQuery("select values.val_name as cname from values,index where values.index_id=index.index_id and index.i_name= '"+ Statename+"'" );*/
    System.out.println("coming here too.......");
    }catch (Exception e){}

    //System.out.println("coming here too.......");
    return (rs);
    }


    }


    state.java
    -----------------
    package cb;

    import java.sql.*;
    public class state extends connection {


    public ResultSet getStates()
    {
    ResultSet rs = null;

    try{
    get_connection();
    rs= st.executeQuery("select * from index1");
    /*rs= st.executeQuery("select * from index");*/

    }catch (Exception e){}
    return (rs);
    }


    }


    connection.java
    ------------------
    package cb;
    import java.sql.*;



    public class connection {
    public String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "C:\\users\\ppreeti\\final_index.accdb";
    public Connection con;
    public Statement st;

    public void get_connection()
    {
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection(url);
    st=con.createStatement();
    }catch(Exception e){}
    }
    public void close_connection()
    {
    try{
    con.close();
    }catch(Exception e){}
    }
    }

    PLZZZZZZZZZ HELP ME ASAP !

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: dynamically related combobox in jsp issue

    ASAP and urgent are no valid arguments here. PLZZZZ doesn't help the slightest.

    Have you ever thought, *if* anybody was willing to fix this, how they were going to get your database? For all the same, the error is in the database content, and not in the code. It's still guesswork.

    And last, "Make me a search button"?? This is not rent-a-coder, you know.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    ppreeti is offline Member
    Join Date
    Mar 2014
    Posts
    17
    Rep Power
    0

    Default Re: dynamically related combobox in jsp issue

    Really sorry if it sounded rude to you ! I'm new to java forums and desperately wanted to fix the issue with the help of experts like you. I've already wasted days figuring out how it could be resolved as I am naive programmer in JSP etc.
    Sorry again ! I was just looking for help !

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: dynamically related combobox in jsp issue

    People here are always willing to help, but this is not a code factory. Help != creating your code for you. Apparently you need to study JSP a bit more to get it working. Word of advice: don't do everything at once. Make sure the database is returning sensible values, then print those as plain text in in HTML, then create a combobox. Coding all in one go will be a disaster.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Problem: Fill a comboBox from another combobox
    By Ridha in forum AWT / Swing
    Replies: 2
    Last Post: 03-08-2013, 02:34 PM
  2. Replies: 1
    Last Post: 04-27-2012, 07:14 AM
  3. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  4. Related to ...
    By siva_vs_siva in forum New To Java
    Replies: 2
    Last Post: 09-09-2010, 05:20 PM
  5. Issue related to browser
    By sachindanayak in forum Java Servlet
    Replies: 0
    Last Post: 02-03-2008, 02:25 AM

Posting Permissions

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