Javascript 在html中重新打印表单输入
因此,我正在为自己设计一个网站,它通过一个表单接收用户的输入,在数据库中搜索相同的内容,并返回预期的输出 下面显示的是我的HTML代码Javascript 在html中重新打印表单输入,javascript,html,jsp,Javascript,Html,Jsp,因此,我正在为自己设计一个网站,它通过一个表单接收用户的输入,在数据库中搜索相同的内容,并返回预期的输出 下面显示的是我的HTML代码 <%@ page import="java.sql.*"%> <%@ include file="DBConn.jsp" %> <%@ page import = "java.sql.*"%> <% String ID,time,result,obj; Statement stmt,stmt2; ResultSet
<%@ 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> </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> </p>
</div>
</body>
</html>
智能跟踪搜索接口
#标题1{
位置:绝对位置;
宽度:100%;
顶部:126px;
能见度:可见;
左:4px;
}
#表1{
位置:绝对位置;
宽度:780px;
高度:408px;
z指数:1;
左:1px;
顶部:272px;
右:自动;
}
#apDiv1{
位置:绝对位置;
宽度:403px;
高度:408px;
z指数:1;
左:自动;
顶部:200px;
右:-1px;
}
.center1{
文本对齐:居中;
}
#apDiv1.indent-1{
文本对齐:居中;
字体大小:44px;
}
#apDiv1 p{
文本对齐:居中;
}
$(文档).ready(函数(){
$(“#login_frm”).submit(函数(){
//删除以前的类并添加新的“myinfo”类
$(“#msgbox”).removeClass().addClass('myinfo').text('Validating Your Login').fadeIn(2000);
this.timer=setTimeout(函数(){
$.ajax({
url:'check.jsp',
数据:'un='+$('#login_id').val()+'&pw='+$('#password').val(),
键入:“post”,
成功:功能(msg){
如果(msg!=“ERROR”)//消息已发送,请检查并重定向
{//并直接进入成功页面
$(“#msgbox”).html('Login-Verified,loggin-in…').addClass('myinfo').fadeTo(900,1,
函数()
{
//重定向到安全页面
document.location='login.jsp?user='+msg;
});
}
其他的
{
$(“#msgbox”).fadeTo(200,0.1,function()//开始淡入messagebox
{
//添加消息并更改框的类别,然后开始淡入淡出
$(this.html('Sorry,用户名和密码的组合错误。')).removeClass().addClass('myerror').fadeTo(900,1);
});
}
}
});
}, 200);
返回false;
});
});
欢迎来到Intelli Track搜索界面
对象标记ID
上次访问的日期和时间
物镜
输入要搜索的对象:
这就是页面的实际外观:
因此,这个页面基本上做的是,当用户在表单中输入一个值(有效值是pen、key、atm、wallet)时,它检索笔访问的最后一次时间和TAG_ID,它已经存储在数据库中。虽然我可以轻松地检索这两个值。我不知道如何在第一列“对象”中打印对象的名称,它应该再次打印有效对象(如笔、钱包、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>
对象标记ID
上次访问的日期和时间
这里有什么。。???
我尝试过使用Document.getElementbyID,但不起作用。。。!!是的,这一点也没有验证 简单地说,如果我没有错,您想显示在文本框
对象查找器中输入的文本吗
如果是,那么您已经在JSP中将其作为字符串obj=request.getParameter(“ID”)检索代码>因此,只要在需要显示值的任何位置使用
,例如:
<tr>
<td align="center">
<%= obj %>
</td>
...
...
我已经为同样的问题找到了解决方案,我让数据库本身存储对象名和标记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>
对象标记ID
上次访问的日期和时间
所以这是我的问题。我知道,是的,但同样没有验证。。!!我只需要把它与数据库匹配时。。!!!美好的在这个问题中,您没有提到数据库表的另一列是objj
。无论如何,如果你能把问题简化成相关的代码,并提供必要的信息,这将对你将来有所帮助。谢谢