私はhtmlラジオボタンを持っています。ユーザーが送信ボタンをクリックすると、その値をデータベーステーブルに追加します。htmlラジオボタンデータベースに追加
4つのラジオボタンは、私はrequest.getParameter()を使用していると私はQ1を引用している---
o a
o b
o c
o d
があります。しかし、データベーステーブルに何が入っているかをチェックすると、「null」が追加されます。 データベースにどのように値を追加しますか?
ここは私のHTMLラジオボタンです。
<FORM ACTION="Question2.jsp">
Q1. This is the section of code that gracefully responds to exceptions.<P>
<INPUT TYPE=RADIO NAME="q1" VALUE="a"/>a. Exception generator<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="b"/>b. Exception manipulator<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="c"/>c. Exception handler<BR>
<INPUT TYPE=RADIO NAME="q1" VALUE="d"/>d. Exception monitor<P>
<INPUT TYPE=SUBMIT VALUE="submit"/>
</FORM>
...ここでは、テーブルに値を追加しようとしています。
<%
String query = "INSERT INTO Quiz2 VALUES (?)";
PreparedStatement pst = (PreparedStatement) conn.prepareStatement(query);
String answer = request.getParameter("q1");
pst.setString(1, answer);
pst.executeUpdate();
%>
System.out.print(answer);しかし、それは何も表示されないjspです。 –
'System.out.print(answer);'はサーバコンソールに値を書き出します。 jspスクリプトレットで 'out.print(answer);'で印刷することができます。 '$ {param.q1}'や '$ {param [q1]}'(スクリプトレット外)、 '<%= request。getParameter( "q1")%> ' – tusar