I have a list of objects in a JSP and want to send a value back to the servlet based on a hyperlink that was clicked. My code is show bellow.
<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>
and servlet GET method:
@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");
}
}
at the moment no information (or at least no value) is being sent to the servlet
You are making a POST request you will not get result in doGet()
try in doPost()
edit in answer based on edit on your post
for this type of operation GET is well suited you could just generate link
as suggested here in your earlier post you should generate link that would pass parameter by URL
with this approach I suspect you are posting at wrong path you could investigate it using firebug
在Servlet中使用JOptionPane确实很奇怪-而是记录一些内容。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.