java - Communication error between jsp and servlet? -


there dropdown list in jsp page in there several websites name e.g google.com etc. , there textbox used keyword search.

also there servlet file used webcrwaling. when select of url dropdown shoukd connect servlet retrive links of particular keyword. how achieve pls help..

.jsp file

<%@ page  import="java.sql.*"  %> <%resultset rs=null; %> <html> <head>  <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>     select website name dropdownlist </title>  <link href="desktop/style.css"  rel="stylesheet"      type="text/css" />         </head> <body bgcolor="8b4513"> <%      connection conn=null;     try     {     class.forname("com.mysql.jdbc.driver").newinstance();     conn=drivermanager.getconnection  ("jdbc:mysql://localhost:3306/tendermysql","root","root");     statement stmt=conn.createstatement(); rs=stmt.executequery("select * record");    %>  <form  action ="search.java"   method="post"> <center> <h1> welcome ezest tender optimzed search</h1> choose website:   <select  name ="url" > <%  while(rs.next())     {         %>     <option   value="<%=rs.getstring(3) %>">     <% out.println(rs.getstring(3)); %>     </option>    <% } %>     </select>   <% }    catch(exception e)     {         out.println("wrong input" +e);     }     %> <br>  enter keyword: <input type="text" name="name" /> <input type="submit" value="submit" /> </center> </form> </body> </html> 

.java file

import java.io.ioexception; import javax.servlet.*; import javax.servlet.http.*; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import org.jsoup.jsoup; import org.jsoup.nodes.document; import java.io.printwriter; import org.jsoup.nodes.element; import org.jsoup.select.elements; public class search extends httpservlet     {      private static final long serialversionuid = 1l;     public static db db = new db();      protected void doget(httpservletrequest request,     httpservletresponse response) throws servletexception, ioexception     {          printwriter out=response.getwriter();            try {             db.runsql2("truncate record;");         } catch (sqlexception e)          {             // todo auto-generated catch block             e.printstacktrace();         }          try {             processpage("http://www.mit.edu", out);         } catch (sqlexception e) {             // todo auto-generated catch block             e.printstacktrace();         } }    public static void    processpage(string url, printwriter out)   throws sqlexception, ioexception     {                 //check if given url in database         string sql = "select * record url_link = '"+url+"'";         resultset rs = db.runsql(sql);         if(rs.next())          {          }         else         {             //store url database avoid parsing again             sql = "insert  `tendermysql`.`record` " + "(`url_link`)              values " + "(?);";             preparedstatement stmt = db.conn.preparestatement             (sql, statement.return_generated_keys);             stmt.setstring(1,url);             stmt.execute();              //get useful information             document doc = jsoup.connect("http://www.mit.edu").get();              if(doc.text().contains("education"))             {                 out.println ("<a href='" +url+ "'>"+url+"</a>" );                }              else             {                 out.println("there no content");             }             out.println("<br/>");             out.println("<br/>");             //get links , recursively call processpage method             elements questions = doc.select("a[href]");             for(element link: questions){                 if(link.attr("href").contains("mit.edu"))                     processpage(link.attr("abs:href"),out);           }         }     }   } 

according jsp file...

<form action="search" id="searchform">     <input type="hidden" name="url" id="url">  <center>  <h1> welcome ezest tender optimzed search</h1> choose website:     <select  name ="url" onchange="submitcall('<%=rs.getstring(2) %>')">     <%      while(rs.next())         {             %>         <option   value="<%=rs.getstring(2) %>">         <% out.println(rs.getstring(2)); %>         </option>         <% } %>         </select>        <% }        catch(exception e)         {             out.println("wrong input" +e);         }         %>     <script>       function submitcall(valueobj)       {             //set in hidden field             $("#url").val(valueobj);             $("#search").submit();         }       </script>   </center>     </form>     </body>      </html> 

and below java file...

        public static void  processpage(string url, printwriter out)          throws sqlexception, ioexception     {                 //check if given url in database         string sql = "select * record url_link = '"+url+"'";         resultset rs = db.runsql(sql);         if(rs.next())          {          }         else         {             //store url database avoid parsing again             sql = "insert  `tendermysql`.`record` " + "                 (`url_link`) values " + "(?);";             preparedstatement stmt = db.conn.preparestatement             (sql, statement.return_generated_keys);             stmt.setstring(1,url);             stmt.execute();              //get useful information             document doc = jsoup.connect("link").get();              if(doc.text().contains("education"))             {                 out.println ("<p>'" +url+ "'>"+url+"</p>" );                }              else             {                 out.println("there no content");             }             out.println("<br/>");             out.println("<br/>");             //get links , recursively call processpage method             elements questions = doc.select("a[href]");             for(element link: questions){                 if(link.attr("href").contains("mit.edu"))                     processpage(link.attr("abs:href"),out);           }         }     } } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -