tags:

views:

21

answers:

1

I am trying to create a an online exam with JSP. I want to get the questions one by one and show them on the screen, and create a "Next" button then user is able to to see the next question, but the problem is that I dont know how to find out that the user has clicked on the "Next" button, I know how to do it in PHP :

if($_SERVER['REQUEST_METHOD']=='GET')
    if($_GET['action']=='Next')

but I dont know how to do it in JSP. Please help me this is piece of my code:

    String result = "";
    if (database.DatabaseManager.getInstance().connectionOK()) {
        database.SQLSelectStatement sqlselect = new database.SQLSelectStatement("question", "question", "0");
        ResultSet _userExist = sqlselect.executeWithNoCondition();
        ResultSetMetaData rsm = _userExist.getMetaData();

        result+="<form  method='post'>";
        result += "<table border=2>";
        for (int i = 0; i < rsm.getColumnCount(); i++) {
            result += "<th>" + rsm.getColumnName(i + 1) + "</th>";
        }

        if (_userExist.next()) {                
            result += "<tr>";
            result += "<td>" + _userExist.getInt(1) + "</td>";
            result += "<td>" + _userExist.getString(2) + "</td>";
            result += "</tr>";
            result += "<tr>";
            result += "<tr> <td colspan='2'>asdas</td></tr>";
            result += "</tr>";                
        }
        result += "</table>";
        result+="<input type='submit' value='next' name='next'/></form>";
    }
+1  A: 

The name-value pairs of all involved HTML input elements are available as request parameters.

<input type="submit" name="action" value="prev">
<input type="submit" name="action" value="next">

with

String action = request.getParameter("action");
if ("prev".equals(action)) {
    // Prev button pressed.
} else if ("next".equals(action)) {
    // Next button pressed.
}

or alternatively,

<input type="submit" name="prev" value="prev">
<input type="submit" name="next" value="next">

with

if (request.getParameter("prev") != null) {
    // Prev button pressed.
} else if (request.getParameter("next") != null) {
    // Next button pressed.
}

That said, template text belongs in a JSP file, not in a Servlet class. I'd suggest to get yourself through those tutorials to learn how to program with JSP/Servlet/MVC/JDBC the right way.

BalusC