下面我们再来看一看,JavaScript对JSP方法和JSP对JavaScript的调用。这两个调用都有一个共同点,那就是需要对页面进行提交,在用Hidden设置几个隐藏参数。JSP根据获得的参数再进行相应的处理,就可以了。也许有的人已经不太明白了,那我们还是用一个程序来说明问题吧!
程序二:一个效劳器获得客户端信息的Web页面。他获得了客户端的一些屏幕设置,并把它们记录在数据库里。
GetClientInfo.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Information</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<STYLE TYPE="text/css">
TABLE, BODY {
font-family: "Courier New";
font-size: 10pt;
}
</STYLE>
</HEAD>
<BODY>
<%
css和html和js怎么结合
Parameter("isHaveData") == null){ %>
<FORM NAME="frmClient" METHOD="POST">
<INPUT TYPE="HIDDEN" NAME="isHaveData" VALUE="">
<INPUT TYPE="HIDDEN" NAME="iScreenWidth">
<INPUT TYPE="HIDDEN" NAME="iColorDepth">
<INPUT TYPE="HIDDEN" NAME="iScreenHeight">
<INPUT TYPE="HIDDEN" NAME="sBrowseName">
<INPUT TYPE="HIDDEN" NAME="sBrowseVer">
<INPUT TYPE="HIDDEN" NAME="iClientHeight">
<INPUT TYPE="HIDDEN" NAME="iClientWidth">
<SCRIPT language="JavaScript1.4" TYPE="TEXT/JAVASCRIPT">          frmClient.iScreenWidth.value = screen.width;
frmClient.iScreenHeight.value = screen.height;
frmClient.iColorDepth.value = lorDepth;
frmClient.sBrowseName.value = navigator.appName;
frmClient.sBrowseVer.value = navigator.appVersion;
frmClient.iClientHeight.value = screen.availHeight;
frmClient.iClientWidth.value = screen.availWidth;
frmClient.submit();
</SCRIPT>
</FORM>
<% } else { %>
<OBJECT id=objMSAgent
classid=CLSID:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F
width="32" height="32">
</OBJECT>
<SCRIPT language="JavaScript1.4" TYPE="TEXT/JAVASCRIPT">
var MerlinID;
var MerlinACS;
objMSAgent.Connected = true;
MerlinLoaded = LoadLocalAgent(MerlinID, MerlinACS);
Merlin = objMSAgent.Characters.Character(MerlinID);
Merlin.Show();
Merlin.Play("Surprised");
Merlin.Speak("<%= "Hello?" %>");
Merlin.Play("GestureLeft");
Merlin.Think("<%= "This is a jsp variant" %>");
Merlin.Play("Pleased");
Merlin.Think("<%= "JavaScript uses jsp variants" %>");
Merlin.Play("GestureDown");
Merlin.Speak("<%= "Bye! so Easy!" %>");
Merlin.Hide();
function LoadLocalAgent(CharID, CharACS) {
LoadReq = objMSAgent.Characters.Load(CharID, CharACS);
return(true);
}
</SCRIPT>
<TABLE>
<TR><TD COLSPAN="2"><FONT COLOR="#FF0000">your infomation:</FONT>
</TD></TR>
<TR><TD>Screen Width:</TD>
<TD><%= Parameter("iScreenWidth") %></TD></TR>
<TR><TD>Screen Height:</TD>
<TD><%= Parameter("iScreenHeight") %></TD></TR>
<TR><TD>Color Depth:</TD>
<TD><%= Parameter("iColorDepth") %></TD></TR>
<TR><TD>Browse Name:</TD>
<TD><%= Parameter("sBrowseName") %></TD></TR>
<TR><TD>Browse Version:</TD>
<TD><%= Parameter("sBrowseVer") %></TD></TR>
<TR><TD>Client area Width:</TD>
<TD><%= Parameter("iClientWidth") %></TD></TR>
<TR><TD>Client area Height:</TD>
<TD><%= Parameter("iClientHeight") %></TD></TR>
</TABLE>
<% String strDSN =
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
+ RealPath("\\WEB-INF\\msg.mdb");
Connection cnct = null;
Statement stmt = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cnct = Connection(strDSN,"","");
stmt = ateStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String strDate = dfNow.format(new java.util.Date());
String sInsertSQL = "INSERT INTO ClientMsg VALUES(" +
"\'" + RemoteAddr() + "\'," +
"\'" + strDate +"\'," +
"\'" + Parameter("iScreenWidth") + "\'," +                  "\'" + Parameter("iScreenHeight") + "\'," +                  "\'" + Parameter("iColorDepth") + "\'," +                  "\'" + Parameter("sBrowseName") + "\'," +                  "\'" + Parameter("sBrowseVer") + "\'," +

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。