버튼을 클릭하면 입력 텍스트 상자 바로 아래에 출력을 표시하는 jquery를 사용하여 코드를 작성했습니다. 표시 할 2 가지가 있습니다 ... 하나는 제곱근입니다. AA 간단한 데이터베이스 쿼리입니다하지만 난 시간이 프로그램은 jquery를 dispay 할 수 없습니다
test4.jsp
<script src="//malsup.github.com/jquery.form.js"></script>
<script type="text/javascript">
$(function(){
$("#hide").click(function()
{
$('#number').fadeOut(2500); //prop('disabled', false);
});
$("#enable").click(function()
{
$('#number').prop('disabled', false);
});
$("#show").click(function()
{
$('#number').show(2500,function()
{
alert("u can enter the values now");
});
});
}); // enable ..show ..hide
$(document).ready(function()
{
$('#form').submit(function() {
var number = $('#number').val();
$.ajax({
type: "post",
url: "test5.jsp",
data: "number=" + number,
success:
function(msg)
{
//$('#result').hide();
//$("#result").html("<h3>" + msg + "</h3>").fadeIn("slow");
$("#result2").html("<h3>" + msg + "</h3>").fadeIn("slow");
}
});
return false;
});
});
</script>
</head>
<body>
<form id="form" action="" method="post">
Enter number:
<input id="number" type="text" name="numb" disabled/>
<input id="enable" type="button" value="Enable">
<input id="show" type="button" value="show">
<input id="hide" type="button" value="hide">
<input id="submit" type="submit" value="Calculate Square Root" name="submit"/>
</form>
<p id="result"></p>
<p id="result2"></p>
test5.jsp 코드
에서 단 1을 표시 할 수 있습니다<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.* ,java.util.*, javax.servlet.*,javax.servlet.http.*, abc.database"%>
<%
int numb = 0;
if(request.getParameter("number").matches("9"))
//if (request.getParameter("number").value
{
numb = Integer.parseInt(request.getParameter("number"));
out.println("Square root of " + numb + " is " + Math.sqrt(numb));
}
else {
out.println("Enter a number!");
}
%>
<%
Connection conn = null ;
ResultSet rs = null;
PreparedStatement ps = null ;
%>
<%
database obj =new database();
conn = obj.connect();
ps = conn.prepareStatement("select field2 from test4 where field1 = "+numb+"");
rs = ps.executeQuery();
while(rs.next())
{
String x = rs.getString(1);
out.println("the value is "+x);
}
conn.close(); rs.close();
%>
참고 -> 내가 용맹 한의 DB 연결이 ..actually 잘 작동 테스트 한 단지 그들 중 하나는 하나 그것은 DB 오/p 또는 제곱근
당신은 당신의 코드를 읽을 수 있는지 확인해야한다 질문을 게시. _js_는 들여 쓰기가 잘못되어 잘못 읽고 형식화됩니다. –
db에서 값을 검색 할 수 있는지 테스트 했습니까 (콘솔에서 값을 경고하거나 로깅 해보십시오)? – Playmaker
@Playmaker 예. .. .. DB 연결이 잘 작동하는지 테스트했습니다. 실제로 그 중 하나만 작동하여 DB o/p 또는 제곱근을 제공합니다. – amol