【发布时间】:2015-03-12 17:37:01
【问题描述】:
我是 Java 和一般编程的新手。作为背景,我正在研究我的简单调查系统。我拥有从 MySQL 中插入和拉取所需的所有类/方法,并在我的 JSP 页面上显示调查。
这是我的 Index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Survey System</title>
</head>
<body>
<h1>Survey List</h1>
<%
ResultSet resultset = new controller.SelectSurvey().SelectSurvey();
if (request.getParameter("btnControlSurvey") != null){
response.sendRedirect("controlsurvey.jsp");
}
if (request.getParameter("btnTakeSurvey") != null){
response.sendRedirect("takesurvey.jsp");
}
%>
<form name = 'surveylist' action="index.jsp" method="POST">
<table border="0">
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<select id="listsurvey">
<% while (resultset.next()) {
%>
<option><%= resultset.getString("survey_ID")%> - <%= resultset.getString("title")%></option>
<% } %>
</select>
</td>
<td>
<input type="submit" value="TAKE SURVEY" name = "btnTakeSurvey" />
</td>
</tr>
</tbody>
<td>
<input type="submit" value="CONTROL SURVEY" name = "btnControlSurvey" />
</td>
</table>
</form>
</body>
单击“提交”按钮后,如何将 ID 为 listsurvey 的下拉列表中选定的surveyID 值传递给 Takesurvey.jsp(见下文)中硬编码的surveyID1 变量?
<%
int surveyID1 = 1;
ResultSet rsSurvey = new controller.SelectSurvey().SelectSurveyByID(surveyID1);
ResultSet rsSurveyQuestion = new controller.SelectSurvey().SelectQuestionByID(surveyID1);
%>
我发现至少有以下三种方法可以做到这一点。什么是最简单的方法,你能给我举个例子吗?
将值放入会话对象中。 将值放入应用程序对象 将值放在重定向 URL 的末尾。
非常感谢您的意见。
谢谢你,祝你有美好的一天。
【问题讨论】:
标签: html jsp jakarta-ee parameters request