私は深刻な問題があります。JSPからJavaScript関数に値を渡す
まず、JSPページ上の個々のスクリプトによってデータベースから値を取得しようとしています。このコードで
<%String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;`
Statement stmt=null;
try{
String url="jdbc:mysql://localhost:3306/MajorProjectDB?user=cdsadmin2&password=enjoyit";
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
String name= request.getRemoteUser();
rst=stmt.executeQuery("select verifycode from Staff where name='"+name+"'");
%>
<%
int no=1;`
while(rst.next()){
%>
<%=no%>
<%=rst.getString("VERIFYCODE")%>
<%String code= request.getParameter("code"); %>
<% } %>
は、私は私のスタッフテーブルのVERIFYCODE列から文字列を格納しています。ここでは、コードの一部です。 getparameter
を使用して、フォーム内のユーザー入力と比較することができます。
ただし、比較はonClick
関数で行う必要がありますが、個々のスクリプトとして実行されているため、onClick
関数には追加できません。
今、私は私のJSPページで、次のJavaScriptでのSQL文を挿入しようとしています:誰もがすべてのソリューションを持っている場合
<script type="text/javascript">
function verifyCode(){
// a SELECT sql statement which gets String from database
//comparison between String retrieved from database and user input
if{
}
else{
}
}
</script>
私が知っているかもしれませんか?それとも簡単な方法がありますか? おかげさまで、お手伝いをさせていただきありがとうございます!
使用してみてください[jQueryのAJAX](HTTP: //api.jquery.com/jQuery.ajax/)を使用して、JSPページにデータを要求し、その要求に対する応答としてデータを返します。 googling abou ** AJAX **を試してみてください –