2010-04-18 4 views
0

저는 JSP로 온라인 시험을 만들려고합니다. 질문을 하나씩 가져 와서 화면에 표시하고 "다음"버튼을 만들면 사용자가 다음 질문을 볼 수 있지만 문제는 사용자가 가지고있는 것을 알아내는 방법을 모르는 것입니다. "다음"버튼을 클릭하면 PHP로 수행하는 방법을 알게되었습니다 :양식이 JSP로 제출되는 것을 확인하는 방법은 무엇입니까?

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

그러나 나는 JSP로하는 법을 모릅니다.

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

관련된 모든 HTML 입력 요소의 이름 - 값 쌍은 요청 매개 변수로 사용할 수 있습니다 제발 도와주세요 이 내 코드의 조각이다. 말했다

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

와 교대로

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

이나와

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

,

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

는 템플릿 텍스트가 아닌 서블릿 클래스, JSP 파일에 속한다. those tutorials을 통해 JSP/Servlet/MVC/JDBC로 프로그래밍하는 법을 배우는 것이 좋습니다.

관련 문제