我的代码如下
<form method="post" action="Answer.jsp">
<input type="submit" value="answer">
<%String q_id=rs.getString("q_id"); %>
<input type="hidden" value="<%out.print(q_id);%>">
</form>
我想将q_id
传递给页面Answer.jsp
我得到了q_id的值,但我不明白如何传递(或使用任何不同的方法)值?
答案 0 :(得分:3)
在您的JSP表单中,您需要
<form method="post" action="Answer.jsp">
<input type="hidden" name="q_id" value="<%= rs.getString("q_id") %>">
<input type="submit" value="Answer">
</form>
然后您可以在 Answer.jsp 中收到q_id
<p>Question ID: <%= request.getParameter("q_id") %></p>
或使用JSP EL(推荐)
<p>Question ID: ${param.q_id}</p>
答案 1 :(得分:0)
在您要隐藏值的页面上。
<form method="post" action="Answer.jsp">
<input type="hidden" id="q_id" name="q_idName" value="someValue">
<input type="submit">
</form>
然后在'Answer.jsp'
页面上,您可以通过调用隐式请求对象的 getParameter(String name)
方法获取值,如下所示:
<% String q_id = request.getParameter("q_idName"); %>
Value : <%=q_id %>