我有一個JSP對象列表,並希望基於單擊的超鏈接將值發送回servlet。我的代碼顯示在下面。從JSP向servlet發送值
<body>
<h1>Choose a Festival</h1>
<jsp:useBean id="allFestivals" type="java.util.ArrayList" scope="session" />
<table border ="1">
<tr>
<td>Festival Name:</td>
<td>Location:</td>
<td>Start Date:</td>
<td>End Date:</td>
<td>URL:</td>
<td>List of Trips to </td>
</tr>
<c:forEach items="${allFestivals}" var="allFestivals">
<tr>
<td>${allFestivals.festivalName}</td>
<td>${allFestivals.location}</td>
<td>${allFestivals.startDate}</td>
<td>${allFestivals.endDate}</td>
<td>${allFestivals.URL}</td>
<td>
//THE ISSUE IS IN THIS FORM, I SUPPOSE SYNTAX ISSUE
<form name="linkChecker" method="get" action="ControllerServlet">
<input type = "hidden" value="${allFestivals.ID}" name="festivalProfileLink" />
<a HREF ="javascript:document.linkChecker.submit()">View Related Trips</a>
</form>
</td>
</tr>
</c:forEach>
</table>
<a href="logout.jsp">Logout</a>
</body>
和servlet GET方法:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String aa = request.getParameter("festivalProfileLink");
JOptionPane.showMessageDialog(null, aa);
if("hello".equals(aa)) {
JOptionPane.showMessageDialog(null, "dfgdfgdf");
}
}
目前沒有信息(或至少沒有價值)被髮送到servlet
非常好看,這樣的答案是爲什麼SO如此之大。 – 2013-04-06 23:13:32
對不起,這是一個錯字,並沒有這不與「得到」(我已編輯的原始帖子) – 2013-04-06 23:20:52
@Jigar我也有類似的問題[這裏](http://stackoverflow.com/questions/22368770/how-to-iterate-an-object-in-jsp-to-get-the-percentage)。看看你能幫助我嗎?任何幫助將不勝感激..感謝您的幫助。 – AKIWEB 2014-03-13 04:36:01