私は、HTMLドロップダウンページからパラメータを取得するサーブレットを持っています。ボタンをクリックすると、データがサーブレットに送信されます。データが初めて送信されたときに動作しますが、ページ上に残り、ドロップダウンメニューから別の値を選択して送信ボタンをクリックすると、新しいデータはセッション変数に設定されません。サーブレットによるセッション変数の変更がありません
私のサーブレットは以下の通りです。 DoGet
メソッドを変更する必要がありますか?繰り返しますが、最初は動作しますが、セッション変数はその後変更されません。
@WebServlet("/ListStudentServlet")
public class ListStudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ListStudentServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sessid = request.getParameter("studentid");
ArrayList<FactStudentDataBean> result = new ArrayList<>();
try (Connection con = JdbcUtil.getConnection()) {
String sql= "select F.Sessionid "
+ "from FACT_STUDENT F "
+ "where studentid = '"+sessid+"';";
try (Statement st = con.createStatement()) {
ResultSet rs = st.executeQuery(sql);
while (rs.next()){
result.add(new FactStudentDataBean(rs.getString(1)));
}
for (FactStudentDataBean factStudentDataBean : result) {
sessid = factStudentDataBean.getSessid();
}
} catch (Exception e) {
e.printStackTrace();
}
}
catch (Exception e) {
e.printStackTrace();
}
//Trying to set the session variable below, works the first time but anything after doesn't change
HttpSession session = request.getSession(true);
session.setAttribute("sessid", sessid);
}
}
'request.getSesを使用する必要があります私はこの質問を参照してください言っていますsion(true) 'は、セッションがまだ存在しない場合に新しいセッションを作成します。セッションクッキーが次のサブミットに設定されていますか? –
どうすれば設定できますか? – thedude865