Hey Guys,
I am making a Online Testing application.
I have one form which sets the settings of the test. The values submitted by the user through this form is passed onto another page.
On the second page the user submits questions and answers.
Now i want the values submitted in both the forms in the two pages to be entered into the database. Please tell me how.
I hope i am clear about the problem.

Dani AI

Generated

The problem is: settings.jsp posts to test.jsp, the user fills questions there, and a single click on test.jsp should save both the earlier settings and the questions. Replies from and noted capturing parameters and saving to the database, but did not show how to carry the settings from page one into the final save or how to do the final save safely. The options below show robust choices and a recommended flow.

Common ways to carry the settings forward

  • Hidden fields: echo the settings into hidden inputs on test.jsp when settings.jsp posts there. Simple and stateless, but values live on the client and are visible/limit-sized. Not ideal for sensitive data.
  • Server session: store a settings object in the HttpSession after the first submit, read it on final submit. Good for sensitive or larger data, but be mindful of memory and session timeouts.
  • Persistent draft: insert a draft test row when the settings are submitted, return a draft id to test.jsp (hidden field), and attach questions to that id on final submit. Best for long flows and resume capability; requires cleanup of abandoned drafts.

Recommended practical flow

  • On settings submit create either a server-side settings object in session or a draft row and return a draft id.
  • On test.jsp include the draft id (if used) or keep relying on the session.
  • On final submit, retrieve the saved settings, validate all inputs server-side, then perform the DB work inside a transaction: insert or update the settings row (if needed) and insert the questions, then commit. Roll back on error and remove the session attribute or mark draft completed.

Example snippets (illustrative):

// save after settings.jsp
TestSettings settings = new TestSettings(...);
session.setAttribute("testSettings", settings);
// final save (in servlet)
TestSettings settings = (TestSettings) session.getAttribute("testSettings");
Connection conn = dataSource.getConnection();
try {
  conn.setAutoCommit(false);
  // insert/update settings and insert questions using PreparedStatement
  conn.commit();
} catch (SQLException e) {
  conn.rollback();
} finally {
  conn.close();
  session.removeAttribute("testSettings");
}

Notes and cautions
Validate everything server-side, use prepared statements to avoid injection, avoid storing very large question lists in session (use draft rows or serialize compactly), enforce session timeouts, and clean up abandoned drafts. This gives an atomic, recoverable flow that answers 's requirement while addressing the gaps in earlier replies.

Recommended Answers

All 3 Replies

There are plenty of examles in this forum and at the java forum on how to connect to the database and execute queries.
So submit the data you want, get them with request.getParameter() and save them to the database

I know how to connect to the database and execute the queries. I dont think you understood my problem.
I have one page settings.jsp which has a form. This form is submitted to the next page test.jsp which also has a form.
Now i want the values submitted in both the forms ie in both the pages settings.jsp and test.jsp to the database after clicking on the submit button on the test.jsp page.
Please tell me how to do this.

Then you did not read reply properly or have no idea what you want as request.getParameter() is all you need

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.