2015-12-20 2 views
4

У меня есть домашняя страница для поиска через него, он содержит текстовое поле и кнопка .. (Страница 1)кнопку подачи без нажатия на нее

Еще одна страница имеет также текстовое поле и кнопку, и под ними есть IFrame показать результаты, когда я нажимаю на поиск .. (Страница 2).

Идея заключается в том, когда я ввожу текст в СТРАНИЦУ 1 и нажимаю кнопку отправки, я хочу перейти на СТРАНИЦА 2 и скопировать текст, введенный на СТРАНИЦ 1, в текстовое поле, которое находится на странице 2, и отправить кнопку без нажатия на кнопку отправки.

Я скопировал текст, но я не знаю, как я могу отправить кнопку?

Page 2 Код:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 
<title> BAK </title> 
<script> 
    function show() { 

     if(document.getElementById("adv").innerHTML == "+") 
     { 
      if(document.getElementById('benefits').style.display=='none') 
      { 
       document.getElementById('benefits').style.display='block'; 
       document.getElementById("adv").innerHTML = "-"; 
      } 
     } 
     else 
     { 
      if(document.getElementById('benefits').style.display=='block') 
      { 
       document.getElementById('benefits').style.display='none'; 
       document.getElementById("adv").innerHTML = "+"; 
      } 
     } 

     return false; 
    } 

    document.theForm.submit(); 

</script> 
<style> 
#searchbox 
{ 
    background-color: #eaf8fc; 
    background-image: linear-gradient(#fff, #d4e8ec); 
    border-radius: 35px;  
    border-width: 1px; 
    border-style: solid; 
    border-color: #c4d9df #a4c3ca #83afb7;    
    width: 525px; 
    height: 35px; 
    padding: 6px; 
    margin: 0px auto 20px; 
    overflow: hidden; /* Clear floats */ 
} 
#search, #submit { 
    float: left; 
} 

#search { 
    padding: 7px 0.5px; 
    height: 35px; 
    width: 380px; 
    border: 1px solid #a4c3ca; 
    font: normal 13px 'trebuchet MS', arial, helvetica; 
    background: #f1f1f1; 
    border-radius: 50px 3px 3px 50px; 
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25) inset, 0 1px 0 rgba(255, 255, 255, 1);  
    padding: 6px; 
} 

#submit 
{  
    background-color: #6cbb6b; 
    background-image: linear-gradient(#95d788, #6cbb6b); 
    border-radius: 3px 50px 50px 3px;  
    border-width: 1px; 
    border-style: solid; 
    border-color: #7eba7C#578e57 #447d43; 
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 
       0 1px 0 rgba(255, 255, 255, 0.3) inset; 
    height: 35px; 
    margin: 0 0 0 10px; 
    padding: 0; 
    width: 90px; 
    cursor: pointer; 
    font: bold 14px Arial, Helvetica; 
    color: #23441e;  
    text-shadow: 0 1px 0 rgba(255,255,255,0.5); 
} 

#submit:hover {  
    background-color: #95d788; 
    background-image: linear-gradient(#6cbb6b, #95d788); 
} 

#submit:active {  
    background: #95d788; 
    outline: none; 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;   
} 

#submit::-moz-focus-inner { 
     border: 0; /* Small centering fix for Firefox */ 
} 

label input { 
    display: none;/* <-- hide the default checkbox */ 
} 
label span {/* <-- style the artificial checkbox */ 
    height: 15px; 
    width: 15px; 
    border-radius:17px; 
    border: 1px solid grey; 
    display: inline-block; 
    position: relative; 
} 
[type=radio]:checked + span:before {/* <-- style its checked state..with a ticked icon */ 
    content: '\2714'; 
    border-radius:17px; 
    position: absolute; 
    top: -2px; 
    left: 0; 
    background: #0C6; 
} 
[type=checkbox]:checked + span:before {/* <-- style its checked state..with a ticked icon */ 
    content: '\2714'; 
    border-radius:17px; 
    position: absolute; 
    top: -2px; 
    left: 0; 
    background: #FFCC00; 
} 
.ss { 
    font-family: 'Helvetica Neue'; 
    font-size: 18px; 
    font-style: italic; 
    font-variant: normal; 
    font-weight: bold; 
    line-height: 22px; 

} 
html { 
    overflow-y: hidden; 
} 
a{ 
    background-color: #FFFFFF; 
    background-image: linear-gradient(#95d788, #FFFFFF); 
    border-radius: 50px 50px 50px 50px;  
    border-width: 1px; 
    border-style: solid; 
    border-color: #7eba7C#578e57 #447d43; 
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.3), 
       0 1px 0 rgba(255, 255, 255, 0.3) inset; 
    height: 33px; 
    margin: 0 0 0 10px; 
    padding: 0; 
    width: 30px; 
    cursor: pointer; 
    font: 28px Arial, Helvetica; 
    color: #23441e;  
    text-shadow: 0 1px 0 rgba(255,255,255,0.5); 
    float: left; 
    text-decoration: none; 
} 
a:hover {  
    background-color: #95d788; 
    background-image: linear-gradient(#FFFFFF, #95d788); 
} 

a:active {  
    background: #95d788; 
    outline: none; 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) inset;   
} 

a::-moz-focus-inner { 
     border: 0; /* Small centering fix for Firefox */ 
} 
</style> 

</head> 

    <body> 
    <form name="theForm" method="post" action="results_Page.jsp" target="iframe"> 
    <% 
     String textSearch = request.getParameter("txtbox").toLowerCase(); 
    %> 
    <div align="center" id="searchbox"> 
     <input id="search" type="text" placeholder=" Type here.." value="<%=textSearch %>" name="txtbox"> 
     <input id="submit" name="submit" type="submit" value="Search"> 
    <a id="adv" href="1" alt="Advance Search" name="1" onclick="return show();">+</a> 
    </div> 

    <div align="center" class="ss"> 


    <div id="benefits" style="display:none;">  
    <table cellpadding="5"> 
      <tr> 
      <td> 
      <label> Search Using : </label> 
      </td> 
      <td> 
      <label><input type="radio" name="se" id="op1" value="boolean_retrieval" checked="checked"><span></span> boolean_retrieval </label> 
      </td>     
      <td> 
      <label><input type="radio" name="se" id="op2" value="Inverted_Index" /> <span></span> Inverted Index model </label> 
      </td> 
      <td> 
      <label><input type="radio" name="se" id="op3" value="Posting_Lists" /> <span></span> Posting Lists model </label> 
      </td> 
      </tr> 

      <tr> 
      <td> 
      <label> Options : </label> 
      </td> 
      <td> 
      <label><input type="checkbox" name="op1" id="op4" value="stop_words"> <span></span> Stop word </label> 
      </td>      
      <td> 
      <label><input type="checkbox" name="op2" id="op5" value="wordNet" /> <span></span> wordNet </label> 
      </td> 
      <td> 
      <label><input type="checkbox" name="op3" id="op6" value="stemming" /> <span></span> Porter Stemmer </label> 
      </td> 
      <td> 
      <label><input type="checkbox" name="op4" id="op7" value="reIndexing" /> <span></span> Re-Indexing </label> 
      </td> 
      </tr> 
    </table> 
    </div> 
    </div> 

    <div> 
     <hr> 
     <iframe name="iframe" src="iframeImage.html" height="500px" width="100%" style=" border-width: 0; image-resolution: snap;" > </iframe> 

    </div> 

    </form> 

</body> 
</html> 

Results_Page.JSP Код:

<%@page import="java.util.Arrays"%> 
<%@page import="java.util.List"%> 
<%@page import="org.jsoup.parser.Parser"%> 
<%@page import="org.jsoup.nodes.Element"%> 
<%@page import="org.jsoup.select.Elements"%> 
<%@page import="org.jsoup.Jsoup"%> 
<%@page import="org.jsoup.nodes.Document"%> 
<%@page import="java.util.StringTokenizer"%> 
<%@page import="java.io.FileReader"%> 
<%@page import="java.io.BufferedReader"%> 
<%@page import="java.util.ArrayList"%> 
<%@page import="java.io.File"%> 
<%@page import="Search.searchEngine"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title> == BAK Results == </title> 
    </head> 
    <body> 
     <div> 

      <h2> ${param.txtbox} </h2> 


       <% 
        List<String> stopwordsList = Arrays.asList("a", "able", "about", 
      "across", "after", "all", "almost", "also", "am", "among", "an", 
      "and", "any", "are", "as", "at", "be", "because", "been", "but", 
      "by", "can", "cannot", "could", "dear", "did", "do", "does", 
      "either", "else", "ever", "every", "for", "from", "get", "got", 
      "had", "has", "have", "he", "her", "hers", "him", "his", "how", 
      "however", "i", "if", "in", "into", "is", "it", "its", "just", 
      "least", "let", "like", "likely", "may", "me", "might", "most", 
      "must", "my", "neither", "no", "nor", "not", "of", "off", "often", 
      "on", "only", "or", "other", "our", "own", "rather", "said", "say", 
      "says", "she", "should", "since", "so", "some", "than", "that", 
      "the", "their", "them", "then", "there", "these", "they", "this", 
      "tis", "to", "too", "twas", "us", "wants", "was", "we", "were", 
      "what", "when", "where", "which", "while", "who", "whom", "why", 
      "will", "with", "would", "yet", "you", "your"); 

        String textSearch = request.getParameter("txtbox").toLowerCase(); 
        String type = request.getParameter("se"); 
        String option1 = request.getParameter("op1"); 
        String option2 = request.getParameter("op2"); 
        String option3 = request.getParameter("op3"); 
        String option4 = request.getParameter("op4"); 


        searchEngine obj = new searchEngine(); 
        obj.search(textSearch, type,option1,option2,option3,option4); 


        ArrayList allFiles = new ArrayList(); 
        allFiles = (ArrayList<Object>)(obj.getAllFilesArray()).clone(); 

        if(allFiles.size() < 1) 
        { 
         %> 
          <div align="left" style=" margin-left: 310px;"> 
           <h4 color="#E8E8E8"> <%="About " + allFiles.size() + " Results." %> </h4> 
          </div> 
         <% 
        } 
        else 
        { 
         for(int i=0;i < allFiles.size();i++) { 
         File xmlFiles = new File((String)(allFiles.get(i))); 
         BufferedReader br = new BufferedReader(new FileReader(xmlFiles)); 

         StringBuilder xmlAsText = new StringBuilder(); 
         String line = ""; 
         line = br.readLine(); 
         while (line != null) { 
          xmlAsText.append(line); 
          xmlAsText.append("\n"); 
          line = br.readLine(); 
         } 
         StringTokenizer descTokenizer = null; 
         Document doc = Jsoup.parse(xmlAsText.toString(),"",Parser.xmlParser()); 

         String image = doc.select("IMAGE").first().text(); 
         Elements titles = doc.getElementsByTag("TITLE"); 
         String titlesText = ""; 
         Elements descriptions = doc.getElementsByTag("DESCRIPTION"); 

         File desktopDir = new File(System.getProperty("user.home"), "Desktop"); 
         String ImagePath="",FilePath=""; 
         ImagePath = "ImageServlet?data=" + desktopDir.getPath() + "\\IRDataset\\iaprtc12\\" + image; 
         FilePath = "FilesServlet?data=" + allFiles.get(i).toString(); 


         String Desc=""; 
         if(descriptions.size() > 0) 
         { 
          descTokenizer = new StringTokenizer(descriptions.get(0).text()," "); 
          while (descTokenizer.hasMoreTokens()) 
          { 
           String word = descTokenizer.nextToken(); 

           if(Desc.length() < 100) 
           { 
            Desc += word +" "; 
           } 
           else 
           { 
            Desc += " .."; 
            break; 
           } 
          } 
          %> 
          <% 
           if(i == 0) 
           { 
            %> 
            <div align="left" style=" margin-left: 310px;"> 
             <h4> <%="About " + allFiles.size() + " Results." %> </h4> 
            </div> 
            <% 
           } 
          %> 
          <a href="<%=FilePath %>" style="color: black"> 

          <div align="left" style=" margin-left: 310px;"> 
           <div align="left" style="display:inline-block;vertical-align:top;"> 
           <img height="80px" width="80px" src="<%=ImagePath %>" alt="<%=titles.get(0).text()%>"/> 
           </div> 
           <div align="left" style="display:inline-block; margin-left: 20px"> 
            <div><h3> <%=titles.get(0).text() + titlesText%> </h3> </div> 
            <div><p><%=Desc%></p></div> 
           </div> 
          </div> 
          </a> 
           <br/> 
          <% 
         } 
        } 
        } 





       %> 

     </div> 
    </body> 
</html> 
+0

Вы были в состоянии решить эту проблему? – Perdomoff

+0

Не решил .. я изменил всю идею –

+0

Дайте мне знать, если вы хотите повторить попытку. – Perdomoff

ответ

2

JavaScript:

document.getElementById("theForm").submit(); 
+0

Не отправлено! –

+0

Ваше действие установлено: action = "results_Page.jsp"; Вы обрабатываете запрос в jsp? – Perdomoff

+0

Да, String textSearch = request.getParameter ("txtbox"). ToLowerCase(); –

2

Изменить тип кнопки поиска, чтобы представить.

<input id="search" type="submit" placeholder=" Type here.." value="<%=textSearch %>" name="txtbox"> 

И потом:

document.getElementByTagName("form").submit(); 
+0

это уже тип отправки, ничего не изменилось! –

Смежные вопросы