微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

dojo之ajax

< label > 输入您要投票的教师工号: < inputtype = " text " name = " tId " id = " name " onmouSEOut = " hellopressed(); " />
< buttondojoType = " Button " widgetId = " helloButton " onClick = " hellopressed(); " > 显示教师信息 </ button >
</ label >

js调用server.jsp页面 显示回来..

< scripttype = " text/javascript " src = " ../dojojs/dojo.js " ></ script >
< scripttype = " text/javascript " >
dojo.require(
" dojo.widget.* " );
</ script >
< script >
function hellopressed()
{
dojo.io.bind(
{
url:
'server.jsp',
method:
'POST',
handler:helloCallback,
content:
{name:dojo.byId('tId').value}
}
);
}


function helloCallback(type,data,evt)
{
if(type=='error')
{
alert(
'读取服务器数据时出错');
}

else
{
dojo.byId(
"show").innerHTML=data;
}

}

</ script >

serve.jsp

<% @pagecontentType = " text/html;charset=GB2312 " %>
<% @pageimport = " java.sql.*,com.teacher.*,com.pool.*; " %>
<%
request.setCharacterEncoding(
" GB2312 " );
%>
<%! Stringr1 = "" ,r2 = "" ,r3 = "" ,r4 = "" ,r5 = "" ,r6 = "" ,r7 = "" ; %>
<%

Stringname
= null ,r7 = new String( "" );
name
= request.getParameter( " name " );
if (name.length() != 0 &&! name.equals( "" ))
{
Connectionconn
=null;
Statementstmt
=null;
ResultSetrs
=null;
Stringsql
="select*fromteacherwheretId="+name+";";
try{
conn
=ConnDB.getConnection();
stmt
=conn.createStatement();
rs
=stmt.executeQuery(sql);
if(rs.next())
{
r1
=rs.getString(1);
r2
=rs.getString(2);
r3
=rs.getString(3);
r4
=rs.getString(4);
r5
=rs.getString(5);
r6
=rs.getString(6);
}
else
{
r7
="没有这个老师!请查询清楚!";
}

}
catch(Exceptionex)
{
ex.printstacktrace();
}

}

if (r7.length() == 0 && r7.equals( "" ))
{
%><table><tr><td><%=r1%></td><td><%=r2%></td><td><%=r3%></td><td><%=r4%></td><td><%=r5%></td><td><%=r6%></td></tr></table>
<table>
<%}
else
{
%>
<tr><td><%=r7%></td></tr>
<%}
%>
</ table >






版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐