我的问题是我在由html页面内的表单填充的servlet类中创建了一个ArrayList。 然后我将我的数组列表传递给打印所有对象的jsp页面。 现在我打印的每个对象都变成了调用servlet的“doGet”方法的“href”。 我需要通过单击链接所选对象的索引。如何将参数从jsp页面传递给servlet?
//这是我的servlet的方法的doGet的实现:
//我知道这是错误的,使用的getAttribute,但我不知道还有什么可以真正发挥作用。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
**String ciao = request.getAttribute("id");** //this is the error
int k = Integer.parseInt(ciao); // this is because i pass a String object and i'm already sure that it will be a number.
String invio = lista.get(k);
request.setAttribute("key", invio);
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/views/es3-item.jsp");
dispatcher.forward(request, response);
}
这是我的jsp(ES3-的List.jsp)页面打印的对象:
<c:forEach var="valore" items="${requestScope.message}" varStatus="theCount">//message is the key to pass the ArrayList "lista" to this jsp page.
<a href ="./es3"> <c:out value="${valore}"/> </a>
<a id="${theCount.index}"></a>
</c:forEach>
的可能重复的形式[如何将数据从JSP转移到servlet中](http://stackoverflow.com/questions/4971877/how-to-transfer-data-from-jsp-to-servlet) – VedX 2015-03-31 12:01:06
你必须通过它的价值附加在url – silentprogrammer 2015-03-31 12:04:47