开发者

how to get data using dropdownlist, textbox and search button in jsp

开发者 https://www.devze.com 2023-01-29 21:46 出处:网络
I want to display data using jsp,javascript and mysql. My Q. is If i select an entry开发者_StackOverflow中文版 suppose \'title\' from dropdownlist and give a title name \'partial dif\' in textbox and

I want to display data using jsp,javascript and mysql. My Q. is If i select an entry开发者_StackOverflow中文版 suppose 'title' from dropdownlist and give a title name 'partial dif' in textbox and click on search button it should show me all the title names that starts with the letters '....par'. Please help me ...........


suppose u have files named form.jsp, form1.jsp... and a table your_table with columns type and name.

    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>form.jsp</title>
    </head>
    <body>
        <form action="form1.jsp" method="post" name=frm>
        <select name="list">
            <option>title</option>
            <option>author</option>
            <option>publication</option>
        </select>
        Name<input type="text" name=txt value=""/>
        <input type="submit" vaue="GO"/>
        </form>
    </body>
</html>

form2.jsp

    <%String list1=request.getParameter("list");
         String name=request.getParameter("txt");
         name1=name.substring(0,3);
          Connection con;
                 PreparedStatement ps,ps1,ps2;
                 ResultSet rs,rs2;
       try{
                 String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
                 String url="jdbc:odbc:rail";
            String username="root";
            String password="root";
            Class.forName(driverName);
            con=DriverManager.getConnection(url,username,password);
             ps=con.prepareStatement("Select name from your_table where type=? and name like ?%);
             ps.setString(1,list1);
             ps.setString(2,name1);
             rs=ps.executeQuery();
             while(rs.next())
             {
               out.println(rs.getString(1));
               }

            }
         catch(Exception e)
         {out.println(e);}   
%>
0

精彩评论

暂无评论...
验证码 换一张
取 消