I want to search the database from servlet depend upon the column name ,if the result found then it has to display the result in a new jsp page . im not getting the output. im attaching code please give me the solution for this
--
Search.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Search organization</title> </head> <body> <form action ="SearchOrg" method=post> <br><br> <br><br> <h3>Search</h3> <input type ="text" name="search" size="50" > <br><br> <input type="submit" value="search" > </form> </body> </html>
SearchOrg.java --//servlet class
import java.io.IOException; import java.io.PrintWriter; import java.sql.DriverManager; import java.sql.ResultSet; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; public class SearchOrg extends HttpServlet { private static final long serialVersionUID = 1L; public void init(ServletConfig config) throws ServletException{ this.setConfig(config); } public void setConfig(ServletConfig config) { } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out =response.getWriter(); response.setContentType("text/html"); String search_org = request.getParameter("search"); // out.println("<TD>Website</TD></TR>"); try{ Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/org_info","root","dhyuti"); Statement stmt ; ResultSet rs; stmt=(Statement) con.createStatement(); rs=stmt.executeQuery("select * from org_details"); boolean Records=rs.next(); //String org_name =rs.getString(1); //String s=rs.getString(8); if(!Records ){ out.println("<p> No Data found </p>"); } else { while(rs.next()){ if((rs.getString(1)).equalsIgnoreCase(search_org)){ out.println(); out.println("<HTML><HEAD><TITLE>Organization List</TITLE>"); out.println("</HEAD>"); out.println("<BODY bgColor=blanchedalmond text=#008000 topMargin=0>"); out.println("<P align=center><FONT face=Helvetica><FONT color=fuchsia style=\"BACKGROUND-COLOR: white\"><BIG><BIG>List of Organization.</BIG></BIG></FONT></P>"); out.println("<P align=center>"); out.println("<TABLE align=center border=1 cellPadding=1 cellSpacing=1 width=\"75%\">"); out.println("<TR>"); out.println("<TD>Organization Name</TD>"); out.println("<TR>"); out.println("<TD>" + rs.getString(1) + "</TD>"); //out.println("<TD>" + s + ">" + s + "</TD>"); out.println("</TR>"); out.println("</TABLE></P>"); out.println("<P> </P></BODY></HTML>"); } } } rs.close(); con.close(); }catch(Exception e){ e.printStackTrace(); } } }