2013-05-20 21 views
0

因此,我正在爲自己設計一個網站,它通過表單從用戶處獲取用戶輸入,在數據庫中搜索相同的內容,並返回預期的輸出。在HTML中重新輸入表格輸入

下面顯示的是我的HTML代碼相同。

<%@ page import="java.sql.*"%> 
<%@ include file="DBConn.jsp" %> 
<%@ page import = "java.sql.*"%> 
<% 

String ID,time,result,obj; 
Statement stmt,stmt2; 
ResultSet rs; 
String SQL=""; 
String k="key"; 
String w="wallet"; 
String p="pen"; 
String a="atm"; 

ID=""; 
time="";  
result=""; 

String save=request.getParameter("bSave"); 
String delete=request.getParameter("BDelete"); 
String search=request.getParameter("BSearch"); 

stmt = con.createStatement(); 

if (search!=null) 
    { 
    obj=request.getParameter("ID"); 
    if(obj.equals(k)) 
    { 
     ID="05447646"; 
    } 
    else if(obj.equals(w)) 
    { 
     ID="05447647"; 
    } 
    else if(obj.equals(p)) 
    { 
     ID="05447649"; 
    } 
    else if(obj.equals(a)) 
    { 
     ID="05447650"; 
    } 
     rs=stmt.executeQuery("Select * from tablename1 where ID='"+ ID +"'"); 
     while(rs.next()) { 
      ID=rs.getString("ID"); 
      time=rs.getString("time"); } 

    } 
%> 

<!DOCTYPE HTML> 

<html> 
    <head> 
     <title>Intelli-Track Search Interface</title> 
     <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
     <meta name="description" content="" /> 
     <meta name="keywords" content="" /> 
     <link href="1.css" rel="stylesheet" /> 
     <style type="text/css"> 
       #Head1{ 
    position: absolute; 
    width: 100%; 
    top: 126px; 
    visibility: visible; 
    left: 4px; 
} 

       #tab1 { 
    position: absolute; 
    width: 780px; 
    height: 408px; 
    z-index: 1; 
    left: 1px; 
    top: 272px; 
    right: auto; 
} 
     #apDiv1 { 
    position: absolute; 
    width: 403px; 
    height: 408px; 
    z-index: 1; 
    left: auto; 
    top: 200px; 
    right: -1px; 
} 
     .center1 { 
    text-align: center; 
} 
     #apDiv1 .indent-1 { 
    text-align: center; 
    font-size: 44px; 
} 
     #apDiv1 p { 
    text-align: center; 
} 
     </style> 
     <script src="js/jquery-1.8.3.min.js"></script> 
     <script src="css/5grid/init.js?use=mobile,desktop,1000px"></script> 
     <script src="js/init.js"></script> 
     <script type="text/javascript"> 
     $(document).ready(function(){ 
     $("#login_frm").submit(function(){ 

      //remove previous class and add new "myinfo" class 
      $("#msgbox").removeClass().addClass('myinfo').text('Validating Your Login ').fadeIn(2000); 


      this.timer = setTimeout(function() { 
       $.ajax({ 
        url: 'check.jsp', 
        data: 'un='+ $('#login_id').val() +'&pw=' + $('#password').val(), 
        type: 'post', 
        success: function(msg){ 
         if(msg != 'ERROR') // Message Sent, check and redirect 
         {    // and direct to the success page 

          $("#msgbox").html('Login Verified, Logging in.....').addClass('myinfo').fadeTo(900,1, 
           function() 
           { 
           //redirect to secure page 
           document.location='login.jsp?user='+msg; 
           }); 

         } 
         else 
         { 
          $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox 
          { 
           //add message and change the class of the box and start fading 
           $(this).html('Sorry, Wrong Combination Of Username And Password.').removeClass().addClass('myerror').fadeTo(900,1); 
          }); 

         } 
        } 

       }); 
      }, 200); 
      return false; 
     });  

    }); 

</script> 
     <noscript> 
      <link rel="stylesheet" href="css/5grid/core.css" /> 
      <link rel="stylesheet" href="css/5grid/core-desktop.css" /> 
      <link rel="stylesheet" href="css/5grid/core-1200px.css" /> 
      <link rel="stylesheet" href="css/5grid/core-noscript.css" /> 
      <link rel="stylesheet" href="css/style.css" /> 
      <link rel="stylesheet" href="css/reset.css" /> 
      <link rel="stylesheet" href="css/structure.css" /> 
      <link rel="stylesheet" href="css/style-desktop.css" /> 
     </noscript> 
     <!--[if lte IE 9]><link rel="stylesheet" href="css/ie9.css" /><![endif]--> 
     <!--[if lte IE 8]><link rel="stylesheet" href="css/ie8.css" /><![endif]--> 
     <!--[if lte IE 7]><link rel="stylesheet" href="css/ie7.css" /><![endif]--> 

    </head> <body> 
    <form name="form1" method="post" action=""> 
    </form> 
    <nav id="nav"> 
       <ul> 
        <li><a href="index.html">Home</a></li> 
        <li><a href="intel.html">About Intelli-Track</a></li> 
        <li><a href="signout.jsp">Logout</a></li> 
        <li><a href="#contact">Contact</a></li> 
       </ul> 
      </nav> 
<div class="image-centered" id="Head1"> 
<header> <h1 align="center">Welcome to <strong>Intelli-Track</strong> Search Interface</h1><hr> 
</header> 

</div> 

<div id="tab1"> 
      <table align="center" width="800" style="border:10px solid #d2d2d2"> 
<tr><th align="center"><h3><u>Object</u></h3></th><th width="234" align="center"><h3><u>Tag-ID</u></h3></th> 
<th width="394" align="center"><h3><u>Last Accessed Date and Time</u></h3></th></tr> 
<tr></tr> 
<tr><td align="center"><script type="text/javascript"> 

     </script> 
     </td><td align="center"><%=ID%></td> 
<td align="center"><%=time%></td> 
</tr> 
</table> 
</div> 

    <div id="apDiv1"> 
     <p>&nbsp;</p> 
     <h3 class="indent-1"> <span class="center1">Object Finder</span>  </h3> 
     <form name="form2" width=70% method="post" action=""> 
     <p> 
     <label for="ID">Enter object to be searched:</label> 
     </p> 
     <p> 
      <input type="text" name="ID" id="IDd"> 
     </p> 
     <p> 
      <input name="BSearch" type="submit" class="button-big" value="Search"> 
        </p> 
     </form> 
     <p>&nbsp;</p> 
    </div> 
    </body> 
</html> 

這是實際頁面的樣子:

enter image description here

那麼這頁基本上做的是,當用戶在表單中輸入的值(有效值是筆, key,atm,wallet),它將檢索筆訪問的最後一次以及已存儲在數據庫中的TAG_ID。雖然我可以輕鬆地檢索這兩個值。我不知道如何在第一列「OBJECT」中打印對象的名稱,它應該打印有效的對象(如筆,錢包,atm,鍵)

我應該在這部分代碼,實現相同。 :

<table align="center" width="800" style="border:10px solid #d2d2d2"> 
    <tr><th align="center"><h3><u>Object</u></h3></th><th width="234" align="center"><h3><u>Tag-ID</u></h3></th> 
    <th width="394" align="center"><h3><u>Last Accessed Date and Time</u></h3></th></tr> 
    <tr></tr> 
    <tr><td align="center"><script type="text/javascript"> 


    what goes here ..??? 

      </script> 
      </td><td align="center"><%=ID%></td> 
    <td align="center"><%=time%></td> 
    </tr> 
    </table> 

我已經嘗試過使用Document.getElementbyID但那不起作用...!是的,那裏也沒有驗證.. !!

回答

0

簡單的說你想顯示文本框中輸入的文本Object Finder如果我沒有錯的話?

如果是,那麼你已經取回在JSP作爲一個字符串obj=request.getParameter("ID");因此就使用<%= obj %>無論你要顯示的數值,是這樣的:

<tr> 
    <td align="center"> 
     <%= obj %> 
    </td> 
... 
+0

是的,我知道,但同樣沒有驗證.. !!我只需要把它與數據庫匹配時。 – rahul888

0

我已經整理出了一個解決方案同樣,我讓數據庫本身將對象名稱與tag_id一起存儲。

所以在那之後,我只是使用select查詢檢索數據庫值,並在表中發佈相同的值。

rs=stmt.executeQuery("Select * from tablename1 where ID='"+ ID +"'"); 
     while(rs.next()) { 
      obj1=rs.getString("objj"); 
      ID=rs.getString("ID"); 
      time=rs.getString("time"); } 

然後打印相同的使用.. !!

<table align="center" width="800" style="border:10px solid #d2d2d2"> 
    <tr><th align="center"><h3><u>Object</u></h3></th><th width="234" align="center"><h3><u>Tag-ID</u></h3></th> 
    <th width="394" align="center"><h3><u>Last Accessed Date and Time</u></h3></th></tr> 
    <tr></tr> 
    <tr><td align="center"><%=obj1%></td><td align="center"><%=ID%></td> 
    <td align="center"><%=time%></td> 
    </tr> 
    </table> 

所以這解決了我的問題。

+0

不錯!在問題中你沒有提到你的數據庫表有另一列作爲'objj'。無論如何,如果您可以將問題縮減到相關代碼並提供必要的信息,它將在未來幫助您。謝謝 –